26 #include <Classes.hpp>
27 #include <Controls.hpp>
28 #include <StdCtrls.hpp>
30 #include <Buttons.hpp>
31 #include <ExtCtrls.hpp>
33 #include <Dialogs.hpp>
34 #include <Graphics.hpp>
35 #include <ComCtrls.hpp>
52 #pragma package(smart_init)
71 TTrain::TTrain(
int Caller,
int RearStartElementIn,
int RearStartExitPosIn, AnsiString InputCode,
int StartSpeedIn,
int MassIn,
double MaxRunningSpeedIn,
72 double MaxBrakeRateIn,
double PowerAtRailIn,
TTrainMode TrainModeIn,
TTrainDataEntry *TrainDataEntryPtrIn,
int RepeatNumberIn,
int IncrementalMinutesIn,
73 int IncrementalDigitsIn,
int SignallerMaxSpeedIn) : RearStartElement(RearStartElementIn), RearStartExitPos(RearStartExitPosIn), HeadCode(InputCode),
74 StartSpeed(StartSpeedIn), Mass(MassIn), MaxRunningSpeed(MaxRunningSpeedIn), MaxBrakeRate(MaxBrakeRateIn), PowerAtRail(PowerAtRailIn),
75 TrainMode(TrainModeIn), TrainDataEntryPtr(TrainDataEntryPtrIn), RepeatNumber(RepeatNumberIn), IncrementalMinutes(IncrementalMinutesIn),
76 IncrementalDigits(IncrementalDigitsIn), SignallerMaxSpeed(SignallerMaxSpeedIn)
87 AnsiString(RearStartExitPosIn) +
"," + AnsiString(InputCode) +
"," + AnsiString(StartSpeedIn) +
"," + AnsiString(MassIn) +
"," +
88 AnsiString(TrainModeIn));
132 for(
int x = 0; x < 4; x++)
141 for(
int x = 0; x < 4; x++)
150 for(
int x = 0; x < 4; x++)
155 for(
int x = 0; x < 4; x++)
159 for(
int x = 0; x < 3; x++)
196 for(
int x = 0; x < 4; x++)
250 throw Exception(
"Error in attempting to delete FrontCodePtr");
254 for(
int x = 0; x < 4; x++)
258 throw Exception(
"Error in attempting to delete BackgroundPtr[" + AnsiString(x) +
"]");
263 for(
int x = 0; x < 4; x++)
267 throw Exception(
"Error in attempting to delete HeadCodeGrPtr[" + AnsiString(x) +
"]");
296 int NextElementPosition, NextEntryPos, ElementLength, SpeedLimit;
362 bool TempDerail =
false;
408 else if((NextElementPosition > -1) && (NextEntryPos > -1))
479 throw Exception(
"Error, LeadElement Exit Connection is NotSet");
489 for(
int x = 0; x < 4; x++)
496 for(
int x = 0; x < 4; x++)
739 if((random(RandRange)) == 0)
756 int LockedVectorNumber;
995 if(BufferLocation ==
"")
1000 if((BufferLocation ==
"") || (BufferLocation != ExpectedLocation))
1062 int NextElementPosition, NextEntryPos;
1086 NextElementPosition = -1;
1089 if((NextElementPosition > -1) && (NextEntryPos > -1))
1207 AnsiString StationName;
1218 throw Exception(
"Error - Stopped at through station but neither lead nor mid elements have a name");
1231 if((NextElementPosition > -1) && (NextEntryPos > -1))
1357 if(TIFEntryPos == 0)
1393 if(NextElementPosition > -1)
1430 AnsiString Loc =
"";
1431 bool LocNamed =
false;
1460 Loc =
"outside railway";
1492 NextElementPosition = -1;
1503 if((NextElementPosition > -1) && (NextEntryPos > -1) && !
SPADFlag)
1521 if((NextElementPosition > -1) && (NextEntryPos > -1))
1559 FirstPair.second).
GetELink() == TempELink))
1564 SecondPair.second).
GetELink() == TempELink))
1578 FirstPair.second).
GetELink() == TempELink))
1583 SecondPair.second).
GetELink() == TempELink))
1597 FirstPair.second).
GetELink() == TempELink))
1602 SecondPair.second).
GetELink() == TempELink))
1632 ContinuationAutoSigEntry.
RouteNumber = RouteNumber;
1635 int NewLastElement = 0, NewLastExitPos = 0;
1653 if(NewLastElement == -1)
1656 throw Exception(
"Error, Connection = -1 in Continuation loop in UpdateTrain");
1659 if(NewLastExitPos == -1)
1661 throw Exception(
"Error, ConnLinkPos = -1 in Continuation loop in UpdateTrain");
1663 LastElement = NewLastElement;
1664 LastExitPos = NewLastExitPos;
1667 if(CumDistance < 1200)
1673 int FirstDistance = 0;
1674 if(CumDistance >= 1200)
1676 FirstDistance = 100;
1680 FirstDistance = 1200 - CumDistance;
1682 if(FirstDistance < 100)
1684 FirstDistance = 100;
1710 if(VectorIT->RouteNumber == RouteNumber)
1757 LockedVectorNumber)))
1916 for(
int x = 0; x < 4; x++)
1923 for(
int x = 0; x < 4; x++)
1949 if((LeadElementTrainID > -1) && (LeadElementTrainID !=
TrainID))
1954 if(OtherTrainEntryPos == -1)
1956 throw Exception(
"Error - OtherTrainEntryPos not set");
1975 int OtherTrainID = -1;
1976 if((MidExitLinkNum == 1) || (MidExitLinkNum == 3) || (MidExitLinkNum == 7) || (MidExitLinkNum == 9))
2067 bool StopRequired =
false;
2080 int NextElementEntryPos = -1;
2081 int NextElementExitPos = -1;
2082 bool TrainOnNextElement =
false;
2083 bool StopSignalAtNextElement =
false;
2084 if(ForwardConnection)
2092 StopSignalAtNextElement = ((NextTrackElement.
Config[NextElementExitPos] ==
Signal) && (NextTrackElement.
Attribute == 0));
2094 if(TrainAtStopLinkPos1 || TrainAtStopLinkPos2 || (ForwardConnection && (TrainOnNextElement || StopSignalAtNextElement)))
2149 throw Exception(
"Error, Straddle shouldn't be LeadMid prior to resetting at exit from UpdateTrain");
2362 if(Code.Length() != 4)
2366 for(
int x = 1; x < 5; x++)
2373 for(
int x = 0; x < 4; x++)
2537 throw Exception(
"Error in GetOffsetValues - Link value wrong");
2550 if((EntryLink == 1) || (EntryLink == 2) || (EntryLink == 4) || (EntryLink == 7))
2565 AnsiString(
VOffset) +
"," + AnsiString(Element) +
"," + AnsiString(EntryPos) +
"," +
HeadCode);
2574 TRect SourceRect, DestRect;
2576 DestRect.init(0, 0, 8, 8);
2579 Graphics::TBitmap *TempGraphic =
new Graphics::TBitmap;
2581 TempGraphic->PixelFormat = pf8bit;
2582 TempGraphic->Width = 16;
2583 TempGraphic->Height = 16;
2589 TempGraphic->Transparent =
true;
2593 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2594 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2600 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2608 else if(TempElement.
SpeedTag == 89)
2612 else if(TempElement.
SpeedTag == 90)
2616 else if(TempElement.
SpeedTag == 91)
2620 else if(TempElement.
SpeedTag == 92)
2624 else if(TempElement.
SpeedTag == 93)
2628 else if(TempElement.
SpeedTag == 94)
2632 else if(TempElement.
SpeedTag == 95)
2636 TempGraphic->Transparent =
true;
2640 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2641 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2643 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2650 for(
int x = 0; x < 40; x++)
2665 TempGraphic->Transparent =
true;
2669 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2670 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2672 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2686 TempGraphic->Transparent =
true;
2690 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2691 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2695 TempGraphic->Canvas->Draw(0, 0, TempElement.
GraphicPtr);
2698 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2703 TempGraphic->Transparent =
true;
2707 int BDVectorPos = -1;
2716 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2721 TempGraphic->Transparent =
true;
2725 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2726 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2728 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2734 TempGraphic->Transparent =
true;
2738 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2739 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2741 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
3007 throw Exception(
"Error, same train on two different bridge tracks");
3053 AnsiString(EntryPos) +
"," +
HeadCode);
3070 throw Exception(
"Error, TrackVectorPosition set but not EntryPos in SetTrainElementID");
3089 AnsiString(EntryPos) +
"," +
HeadCode);
3098 throw Exception(
"Error, TrackVectorPosition set but not EntryPos in ResetTrainElementID");
3131 AnsiString(ElementEntryPos) +
"," + AnsiString(
HOffset) +
"," + AnsiString(
VOffset) +
"," + AnsiString(StraddleValue) +
"," +
HeadCode);
3132 int LockedVectorNumber;
3145 TRect SourceRect, DestRect;
3146 DestRect.init(0, 0, 8, 8);
3153 int FirstELink, SecondELink = -1;
3156 if(RoutePair2.first > -1)
3165 if(SecondELink == -1)
3167 throw Exception(
"Error - Second ELink should be set but isn't in PlotAlternativeTrackRouteGraphic [1]");
3172 throw Exception(
"Error - First & Second ELinks have same value in PlotAlternativeTrackRouteGraphic");
3182 Graphics::TBitmap *DestGraphic =
new Graphics::TBitmap;
3183 DestGraphic->PixelFormat = pf8bit;
3184 DestGraphic->Width = 8;
3185 DestGraphic->Height = 8;
3186 DestGraphic->Transparent =
true;
3189 DestGraphic->Canvas->CopyRect(DestRect, RouteElement.
GetRouteEXGraphicPtr()->Canvas, SourceRect);
3198 PrefDirElement, LockedVectorNumber))
3213 if(ElementEntryPos > 1)
3235 AnsiString(EntryPos) +
"," +
HeadCode);
3237 bool WrongRoute =
false;
3263 int LinkNumber = TrackElement.
Link[EntryPos];
3264 if((LinkNumber == 1) || (LinkNumber == 3) || (LinkNumber == 7) || (LinkNumber == 9))
3269 bool LogActionErrorCalled =
false;
3279 LogActionErrorCalled =
true;
3296 else if(LinkNumber == 3)
3304 LogActionErrorCalled =
true;
3321 else if(LinkNumber == 7)
3329 LogActionErrorCalled =
true;
3346 else if(LinkNumber == 9)
3354 LogActionErrorCalled =
true;
3386 else if((RouteElement.
GetELinkPos() == 2) && (EntryPos == 0) && PointsAtElement)
3391 else if((RouteElement.
GetELinkPos() == 0) && (EntryPos == 2) && PointsAtElement)
3401 else if((RouteElement.
GetXLinkPos() == 2) && (EntryPos == 0) && PointsAtElement)
3406 else if((RouteElement.
GetXLinkPos() == 0) && (EntryPos == 2) && PointsAtElement)
3415 throw Exception(
"Error, Element in route but no route found in CheckAndCancelRouteForWrongEndEntry");
3436 bool ColourError =
false, ColourError2 =
false;
3441 ColourError2 =
true;
3443 for(
int x = 0; x < 4; x++)
3448 ColourError2 =
true;
3454 "ERROR: Colour depth insufficient to display train colours properly. Please ensure that the 'safe' (web) palette of 256 colours can be displayed");
3458 for(
int x = 0; x < 4; x++)
3545 AnsiString(EntryPos) +
"," +
HeadCode);
3546 int EntryHalfLength, CurrentElementHalfLength, NextElementHalfLength, CumulativeLength = 0, CurrentTrackVectorPosition = TrackVectorPosition;
3547 int DistanceAtHalfBraking, DistanceAtThreeQuarterBraking, ExitPos, NextTrackVectorPosition, NextEntryPos;
3548 bool RedSignalFlag =
false, BuffersFlag =
false, StationFlag =
false, BuffersOrContinuationNowFlag =
false, ContinuationNextFlag =
false,
3549 TrainInFrontInSignallerModeFlag =
false;
3550 double LimitingSpeed, FrontElementMaxSpeed, MaxExitSpeedAtHalfBrakingSquared, MaxExitSpeedAtHalfBraking, NextSpeedLimit, TempBrakeRate;
3551 double ExitSpeedHalfSquared, ExitSpeedFullSquared;
3552 bool SignallerStopRequired =
false;
3563 if(CurrentTrackVectorPosition > -1)
3567 if((EntryPos == 0) || (EntryPos == 2))
3580 else if(EntryPos == 1)
3604 EntryHalfLength = CurrentElementHalfLength;
3609 throw Exception(
"Error - CurrentTrackVectorPosition < 0 in SetTrainMovementValues");
3613 throw Exception(
"Error - HalfLength or SpeedLimit < 0 in SetTrainMovementValues");
3660 FrontElementMaxSpeed = LimitingSpeed;
3695 double ExitSpeedAtMaxBraking;
3700 ExitSpeedAtMaxBraking = 0;
3710 if(ExitSpeedAtMaxBraking > LimitingSpeed)
3712 SpeedToUse = ExitSpeedAtMaxBraking;
3716 SpeedToUse = LimitingSpeed;
3731 RedSignalFlag =
false;
3732 BuffersFlag =
false;
3733 StationFlag =
false;
3734 BuffersOrContinuationNowFlag =
false;
3735 ContinuationNextFlag =
false;
3738 CumulativeLength += (2 * CurrentElementHalfLength);
3741 SignallerStopRequired =
true;
3763 bool StopRequired =
false;
3777 StationFlag =
false;
3783 BuffersOrContinuationNowFlag =
true;
3785 if(!BuffersOrContinuationNowFlag && !BuffersFlag && !StationFlag)
3789 if((EntryPos == 0) || (EntryPos == 2))
3811 if(NextTrackVectorPosition > -1)
3816 if((NextEntryPos == 0) || (NextEntryPos == 2))
3829 else if(NextEntryPos == 1)
3842 if(NextEntryPos > 1)
3856 throw Exception(
"Error - Trying to access NextTrackVectorPosition when none present in SetTrainMovementValues");
3868 RedSignalFlag =
true;
3890 TrainInFrontInSignallerModeFlag =
true;
3914 if(RedSignalFlag || BuffersFlag || StationFlag || TrainInFrontInSignallerModeFlag || SignallerStopRequired ||
StepForwardFlag)
3926 double MaxHalfSpeed;
3930 if(MaxHalfSpeedAtHalfBraking > FrontElementMaxSpeed)
3932 MaxHalfSpeed = FrontElementMaxSpeed;
3936 MaxHalfSpeed = MaxHalfSpeedAtHalfBraking;
3944 bool HalfSpeedLimited =
false;
3948 HalfSpeedLimited =
true;
3978 if(HalfSpeedLimited)
4003 if(SignallerStopRequired)
4019 int TempMaxExitSpeed;
4022 if(MaxExitSpeedAtHalfBrakingSquared < 10)
4024 MaxExitSpeedAtHalfBraking = 0;
4028 MaxExitSpeedAtHalfBraking = sqrt(MaxExitSpeedAtHalfBrakingSquared);
4032 if(MaxExitSpeedAtHalfBraking > FrontElementMaxSpeed)
4034 TempMaxExitSpeed = FrontElementMaxSpeed;
4038 TempMaxExitSpeed = MaxExitSpeedAtHalfBraking;
4050 if(ExitSpeedHalfSquared < 10)
4060 if(ExitSpeedFullSquared < 10)
4132 double DeltaRemainingTimeInSecs = 3.6 * RemainingDistance /
MaxExitSpeed;
4133 ExitTimeFull =
EntryTime + TDateTime((DeltaExitTimeToMaxInSecs + DeltaRemainingTimeInSecs) / 86400.0);
4157 double DeltaRemainingTimeInSecs = 3.6 * RemainingDistance /
MaxExitSpeed;
4158 ExitTimeHalf =
EntryTime + TDateTime((DeltaExitTimeToMaxInSecs + DeltaRemainingTimeInSecs) / 86400.0);
4168 if(!BuffersOrContinuationNowFlag)
4170 if(NextSpeedLimit < LimitingSpeed)
4172 LimitingSpeed = NextSpeedLimit;
4176 int TempMaxExitSpeed;
4180 if(MaxExitSpeedAtHalfBrakingSquared < 10)
4182 MaxExitSpeedAtHalfBraking = 0;
4186 MaxExitSpeedAtHalfBraking = sqrt(MaxExitSpeedAtHalfBrakingSquared);
4188 if(MaxExitSpeedAtHalfBraking > FrontElementMaxSpeed)
4190 TempMaxExitSpeed = FrontElementMaxSpeed;
4194 TempMaxExitSpeed = MaxExitSpeedAtHalfBraking;
4205 TempBrakeRate = ((
EntrySpeed *
EntrySpeed) - (LimitingSpeed * LimitingSpeed)) / 3.6 / 3.6 / 2 / CumulativeLength;
4218 if(!BuffersOrContinuationNowFlag)
4220 CurrentTrackVectorPosition = NextTrackVectorPosition;
4221 EntryPos = NextEntryPos;
4222 CurrentElementHalfLength = NextElementHalfLength;
4225 ContinuationNextFlag =
true;
4229 while(((CumulativeLength -
FrontElementLength) < DistanceAtHalfBraking) && ((!BuffersOrContinuationNowFlag && !ContinuationNextFlag) ||
4249 if(ExitSpeedHalfSquared < 10)
4259 if(ExitSpeedFullSquared < 10)
4322 double DeltaExitTimeToMaxInSecs;
4323 double DistanceToMax;
4332 DeltaExitTimeToMaxInSecs = 2 * EntryHalfLength * 3.6 /
EntrySpeed;
4334 DistanceToMax = EntryHalfLength;
4337 double DeltaRemainingTimeInSecs = 3.6 * RemainingDistance /
MaxExitSpeed;
4338 ExitTimeFull =
EntryTime + TDateTime((DeltaExitTimeToMaxInSecs + DeltaRemainingTimeInSecs) / 86400.0);
4355 double DeltaExitTimeToMaxInSecs;
4356 double DistanceToMax;
4365 DeltaExitTimeToMaxInSecs = 2 * EntryHalfLength * 3.6 /
EntrySpeed;
4367 DistanceToMax = EntryHalfLength / 2;
4370 double DeltaRemainingTimeInSecs = 3.6 * RemainingDistance /
MaxExitSpeed;
4371 ExitTimeHalf =
EntryTime + TDateTime((DeltaExitTimeToMaxInSecs + DeltaRemainingTimeInSecs) / 86400.0);
4382 if(ExitSpeedHalfSquared < 10)
4392 if(ExitSpeedFullSquared < 10)
4411 if((EntryPos == 0) || (EntryPos == 2))
4433 if(NextTrackVectorPosition > -1)
4435 int NextElementLength;
4436 if(NextEntryPos > 1)
4444 double NextStoppingSpeed = sqrt(3.6 * 3.6 * 2 *
BrakeRate * NextElementLength);
4637 int CurrentTrackVectorPosition =
LeadElement, NextTrackVectorPosition;
4655 CurrentTrackVectorPosition).
Attribute != 4))
4694 if((EntryPos == 0) || (EntryPos == 2))
4716 CurrentTrackVectorPosition = NextTrackVectorPosition;
4717 EntryPos = NextEntryPos;
4741 throw Exception(
"Error - failed to set ReturnVal in ClearToNextSignal()");
4766 bool PlatformFoundFlag =
false, StopRequired =
false, SkipRouteCheck =
false, RouteOrPartRouteSet =
false;
4767 int CurrentTrackVectorPosition =
LeadElement, NextTrackVectorPosition, ElementNumber = 0, Distance = 0;
4768 int RouteStartPosition;
4770 int PlatformPosition;
4772 int EntryPos =
LeadEntryPos, ExitPos, NextEntryPos, RouteID;
4788 if(Distance > (4000 + LeadElementDistance))
4811 if(OtherTrain.
LeadElement == CurrentTrackVectorPosition)
4814 if((OtherCommand ==
"Fjo") || (OtherCommand ==
"jbo") || (OtherCommand ==
"cdt") || (OtherCommand ==
"Frh") ||
4860 if(!PlatformFoundFlag)
4862 PlatformPosition = CurrentTrackVectorPosition;
4865 PlatformFoundFlag =
true;
4881 if((EntryPos == 0) || (EntryPos == 2))
4925 if(ElementNumber < 2)
4927 SkipRouteCheck =
true;
4931 SkipRouteCheck =
false;
4933 if(ElementNumber == 1)
4935 RouteStartPosition = CurrentTrackVectorPosition;
4945 if(ElementNumber > 1)
4949 RouteOrPartRouteSet =
true;
4953 RouteOrPartRouteSet =
false;
4956 if(!SkipRouteCheck && !RouteOrPartRouteSet)
4963 int ExitLink = CurrentTrackElement.
Link[ExitPos];
4964 if((ExitLink == 1) || (ExitLink == 3) || (ExitLink == 7) || (ExitLink == 9))
4976 Distance += CurrentTrackElement.
Length01;
4980 Distance += CurrentTrackElement.
Length23;
4982 NextTrackVectorPosition = CurrentTrackElement.
Conn[ExitPos];
4983 NextEntryPos = CurrentTrackElement.
ConnLinkPos[ExitPos];
4984 CurrentTrackVectorPosition = NextTrackVectorPosition;
4985 EntryPos = NextEntryPos;
5022 return(RepeatHeadCode);
5044 bool FrontValid =
false, RearValid =
false;
5045 TTrackElement FrontAdjacentTrackElement, RearAdjacentTrackElement;
5049 TrainToBeJoinedBy = NULL;
5063 int TrainToBeJoinedByID = -1;
5084 if((TrainToBeJoinedByID < 0) && RearValid)
5103 if(TrainToBeJoinedByID < 0)
5105 TrainToBeJoinedBy = NULL;
5110 if(!TrainToBeJoinedBy->
Stopped())
5112 TrainToBeJoinedBy = NULL;
5123 TDateTime TimetableNonRepeatTime,
bool Warning)
5158 AnsiString(ActionType) +
"," + LocationName +
"," +
HeadCode);
5159 AnsiString BaseLog =
"", WarningBaseLog =
"", PerfLog =
"", ActionLog =
"";
5160 int IntMinsLate = 0;
5165 ActionLog =
" arrived at ";
5174 ActionLog =
" terminated at ";
5179 ActionLog =
" departed from ";
5181 if(ActionType ==
Pass)
5183 ActionLog =
" passed ";
5187 ActionLog =
" created at ";
5189 if(ActionType ==
Enter)
5191 ActionLog =
" entered railway at ";
5193 if(ActionType ==
Leave)
5195 ActionLog =
" left railway at ";
5199 ActionLog =
" split from front to ";
5203 ActionLog =
" split from rear to ";
5207 ActionLog =
" joined by ";
5211 ActionLog =
" changed direction at ";
5215 ActionLog =
" became new service ";
5219 ActionLog =
" taken under signaller control at ";
5223 ActionLog =
" restored to timetable control at ";
5229 ActionLog =
" REMOVED FROM RAILWAY DUE TO CRASH at ";
5233 ActionLog =
" REMOVED FROM RAILWAY DUE TO DERAILMENT at ";
5237 ActionLog =
" REMOVED FROM RAILWAY at ";
5242 ActionLog =
" received signaller authority to proceed";
5246 ActionLog =
" received signaller authority to step forward";
5250 ActionLog =
" changed direction under signaller control at ";
5254 ActionLog =
" received signaller authority to pass red signal";
5258 ActionLog =
" received signaller instruction to stop";
5262 ActionLog =
" stopped on signaller instruction ";
5266 ActionLog =
" joined under signaller control by ";
5270 ActionLog =
" suffered an onboard power failure at ";
5274 ActionLog =
" failure repaired at ";
5278 ActionLog =
" left railway under signaller control at ";
5280 if(OtherHeadCode !=
"")
5282 OtherHeadCode +=
" at ";
5289 WarningBaseLog =
HeadCode + ActionLog + OtherHeadCode + LocationName;
5295 bool TimePerformance =
true;
5303 TimePerformance =
false;
5307 double MinsLate = ((double)(ActualTime -
GetTrainTime(1, TimetableNonRepeatTime))) * 1440;
5309 if(ActionType ==
Pass)
5323 IntMinsLate = int(ceil(MinsLate));
5327 IntMinsLate = int(floor(MinsLate));
5329 if(IntMinsLate == 0)
5331 PerfLog =
" on time";
5333 else if(IntMinsLate == 1)
5335 PerfLog =
" 1 minute late";
5337 else if(IntMinsLate == -1)
5339 PerfLog =
" 1 minute early";
5341 else if(IntMinsLate > 1)
5343 PerfLog =
" " + AnsiString(IntMinsLate) +
" minutes late";
5345 else if(IntMinsLate < -1)
5347 int PosIntMinsLate = -IntMinsLate;
5348 PerfLog =
" " + AnsiString(PosIntMinsLate) +
" minutes early";
5350 if(LocationName.Pos(
'-') > 0)
5352 PerfLog =
"," + PerfLog;
5366 if((ActionType ==
Arrive) && (IntMinsLate == 0))
5370 else if((ActionType ==
Arrive) && (IntMinsLate > 0))
5375 else if((ActionType ==
Arrive) && (IntMinsLate < 0))
5381 else if((ActionType ==
Pass) && (IntMinsLate == 0))
5385 else if((ActionType ==
Pass) && (IntMinsLate > 0))
5390 else if((ActionType ==
Pass) && (IntMinsLate < 0))
5396 else if((ActionType ==
Leave) && (IntMinsLate == 0))
5400 else if((ActionType ==
Leave) && (IntMinsLate > 0))
5405 else if((ActionType ==
Leave) && (IntMinsLate < 0))
5411 else if((ActionType ==
Depart) && (IntMinsLate == 0))
5415 else if((ActionType ==
Depart) && (IntMinsLate > 0))
5434 AnsiString LocName =
"";
5501 if(LocationName ==
"")
5505 int FirstNamedElementPos, SecondNamedElementPos, FirstNamedLinkedElementPos, SecondNamedLinkedElementPos;
5506 int RearTrainRearPosition, RearTrainFrontPosition, RearTrainExitPos;
5507 int FrontTrainRearPosition, FrontTrainFrontPosition, FrontTrainExitPos;
5511 if(LocationName !=
"")
5519 SecondNamedElementPos, FirstNamedLinkedElementPos, SecondNamedLinkedElementPos))
5524 SecondNamedElementPos, FirstNamedLinkedElementPos, SecondNamedLinkedElementPos))
5538 int LeadPosA = FirstNamedElementPos;
5539 int LeadPosB = FirstNamedLinkedElementPos;
5540 int LeadPosC = SecondNamedElementPos;
5541 int LeadPosD = SecondNamedLinkedElementPos;
5543 int LeadNumAtLoc = 0;
5560 if(LeadNumAtLoc < 4)
5564 SecondNamedLinkedElementPos))
5566 FirstNamedElementPos = LeadPosA;
5567 FirstNamedLinkedElementPos = LeadPosB;
5568 SecondNamedElementPos = LeadPosC;
5569 SecondNamedLinkedElementPos = LeadPosD;
5573 int MidNumAtLoc = 0;
5590 if(LeadNumAtLoc > MidNumAtLoc)
5593 FirstNamedElementPos = LeadPosA;
5594 FirstNamedLinkedElementPos = LeadPosB;
5595 SecondNamedElementPos = LeadPosC;
5596 SecondNamedLinkedElementPos = LeadPosD;
5610 throw Exception(
"Error - LocationName not set in FrontTrainSplit");
5620 FrontTrainFrontPosition = FirstNamedLinkedElementPos;
5621 FrontTrainRearPosition = FirstNamedElementPos;
5622 RearTrainFrontPosition = SecondNamedElementPos;
5623 RearTrainRearPosition = SecondNamedLinkedElementPos;
5627 FrontTrainFrontPosition = SecondNamedLinkedElementPos;
5628 FrontTrainRearPosition = SecondNamedElementPos;
5629 RearTrainFrontPosition = FirstNamedElementPos;
5630 RearTrainRearPosition = FirstNamedLinkedElementPos;
5637 FrontTrainFrontPosition = SecondNamedLinkedElementPos;
5638 FrontTrainRearPosition = SecondNamedElementPos;
5639 RearTrainFrontPosition = FirstNamedElementPos;
5640 RearTrainRearPosition = FirstNamedLinkedElementPos;
5644 FrontTrainFrontPosition = FirstNamedLinkedElementPos;
5645 FrontTrainRearPosition = FirstNamedElementPos;
5646 RearTrainFrontPosition = SecondNamedElementPos;
5647 RearTrainRearPosition = SecondNamedLinkedElementPos;
5650 RearTrainExitPos = -1;
5651 for(
int x = 0; x < 4; x++)
5655 RearTrainExitPos = x;
5659 if(RearTrainExitPos == -1)
5661 throw Exception(
"Error - RearTrainRearPosition not linked to RearTrainFrontPosition in FrontTrainSplit");
5663 FrontTrainExitPos = -1;
5664 for(
int x = 0; x < 4; x++)
5668 FrontTrainExitPos = x;
5672 if(FrontTrainExitPos == -1)
5674 throw Exception(
"Error - FrontTrainRearPosition not linked to FrontTrainFrontPosition in FrontTrainSplit");
5677 int TrainIDOnRearOfRearTrain, TrainIDOnFrontOfRearTrain, TrainIDOnRearOfFrontTrain, TrainIDOnFrontOfFrontTrain;
5684 else if((RearMostElement.
TrackType ==
Bridge) && (RearTrainExitPos < 2))
5704 else if((FrontMostElement.
TrackType ==
Bridge) && (FrontTrainExitPos < 2))
5712 if(((TrainIDOnRearOfRearTrain > -1) && (TrainIDOnRearOfRearTrain !=
TrainID)) || ((TrainIDOnFrontOfRearTrain > -1) && (TrainIDOnFrontOfRearTrain !=
TrainID)
5713 ) || ((TrainIDOnRearOfFrontTrain > -1) && (TrainIDOnRearOfFrontTrain !=
TrainID)) ||
5714 ((TrainIDOnFrontOfFrontTrain > -1) && (TrainIDOnFrontOfFrontTrain !=
TrainID)))
5811 if(LocationName ==
"")
5815 int FirstNamedElementPos, SecondNamedElementPos, FirstNamedLinkedElementPos, SecondNamedLinkedElementPos;
5816 int RearTrainRearPosition, RearTrainFrontPosition, RearTrainExitPos;
5817 int FrontTrainRearPosition, FrontTrainFrontPosition, FrontTrainExitPos;
5821 if(LocationName !=
"")
5828 SecondNamedLinkedElementPos))
5832 SecondNamedLinkedElementPos))
5846 int LeadPosA = FirstNamedElementPos;
5847 int LeadPosB = FirstNamedLinkedElementPos;
5848 int LeadPosC = SecondNamedElementPos;
5849 int LeadPosD = SecondNamedLinkedElementPos;
5851 int LeadNumAtLoc = 0;
5868 if(LeadNumAtLoc < 4)
5872 SecondNamedLinkedElementPos))
5874 FirstNamedElementPos = LeadPosA;
5875 FirstNamedLinkedElementPos = LeadPosB;
5876 SecondNamedElementPos = LeadPosC;
5877 SecondNamedLinkedElementPos = LeadPosD;
5881 int MidNumAtLoc = 0;
5898 if(LeadNumAtLoc > MidNumAtLoc)
5901 FirstNamedElementPos = LeadPosA;
5902 FirstNamedLinkedElementPos = LeadPosB;
5903 SecondNamedElementPos = LeadPosC;
5904 SecondNamedLinkedElementPos = LeadPosD;
5918 throw Exception(
"Error - LocationName not set in RearTrainSplit");
5928 FrontTrainFrontPosition = FirstNamedLinkedElementPos;
5929 FrontTrainRearPosition = FirstNamedElementPos;
5930 RearTrainFrontPosition = SecondNamedElementPos;
5931 RearTrainRearPosition = SecondNamedLinkedElementPos;
5935 FrontTrainFrontPosition = SecondNamedLinkedElementPos;
5936 FrontTrainRearPosition = SecondNamedElementPos;
5937 RearTrainFrontPosition = FirstNamedElementPos;
5938 RearTrainRearPosition = FirstNamedLinkedElementPos;
5945 FrontTrainFrontPosition = SecondNamedLinkedElementPos;
5946 FrontTrainRearPosition = SecondNamedElementPos;
5947 RearTrainFrontPosition = FirstNamedElementPos;
5948 RearTrainRearPosition = FirstNamedLinkedElementPos;
5952 FrontTrainFrontPosition = FirstNamedLinkedElementPos;
5953 FrontTrainRearPosition = FirstNamedElementPos;
5954 RearTrainFrontPosition = SecondNamedElementPos;
5955 RearTrainRearPosition = SecondNamedLinkedElementPos;
5958 RearTrainExitPos = -1;
5959 for(
int x = 0; x < 4; x++)
5963 RearTrainExitPos = x;
5967 if(RearTrainExitPos == -1)
5969 throw Exception(
"Error - RearTrainRearPosition not linked to RearTrainFrontPosition in RearTrainSplit");
5971 FrontTrainExitPos = -1;
5972 for(
int x = 0; x < 4; x++)
5976 FrontTrainExitPos = x;
5980 if(FrontTrainExitPos == -1)
5982 throw Exception(
"Error - FrontTrainRearPosition not linked to FrontTrainFrontPosition in RearTrainSplit");
5985 int TrainIDOnRearOfRearTrain, TrainIDOnFrontOfRearTrain, TrainIDOnRearOfFrontTrain, TrainIDOnFrontOfFrontTrain;
5992 else if((RearMostElement.
TrackType ==
Bridge) && (RearTrainExitPos < 2))
6012 else if((FrontMostElement.
TrackType ==
Bridge) && (FrontTrainExitPos < 2))
6020 if(((TrainIDOnRearOfRearTrain > -1) && (TrainIDOnRearOfRearTrain !=
TrainID)) || ((TrainIDOnFrontOfRearTrain > -1) && (TrainIDOnFrontOfRearTrain !=
TrainID)
6021 ) || ((TrainIDOnRearOfFrontTrain > -1) && (TrainIDOnRearOfFrontTrain !=
TrainID)) ||
6022 ((TrainIDOnFrontOfFrontTrain > -1) && (TrainIDOnFrontOfFrontTrain !=
TrainID)))
6161 TTrain *TrainToBeJoinedBy;
6194 double OtherBrakeForce = TrainToBeJoinedBy->
MaxBrakeRate * TrainToBeJoinedBy->
Mass;
6196 double CombinedBrakeRate = (OtherBrakeForce + OwnBrakeForce) / (TrainToBeJoinedBy->
Mass +
Mass);
6253 int RouteNumber = -1;
6261 bool FirstPass =
true;
6266 if(FirstPass && (TVPos2 != FirstRouteElementVecPos))
6369 for(
int x = 0; x < IncNum; x++)
6402 else if(Ptr->
Command ==
"jbo")
6413 throw Exception(
"Error - illegal command in SendMissedActionLogs for IncNum = " + AnsiString(IncNum) +
", and command = " + Ptr->
Command);
6419 bool IncludeFER =
false;
6427 if(!IncludeFER && (Ptr->
Command ==
"Fer"))
6432 else if(IncludeFER && (Ptr->
Command ==
"Fer"))
6443 else if(Ptr->
Command ==
"Fjo")
6449 else if(Ptr->
Command ==
"Frh")
6459 else if(Ptr->
Command ==
"Frh-sh")
6510 else if(Ptr->
Command ==
"jbo")
6515 else if(Ptr->
Command ==
"cdt")
6523 throw Exception(
"Error - illegal command in SendMissedActionLogs for IncNum = " + AnsiString(IncNum) +
", and command = " + Ptr->
Command);
6895 int RouteNumber = -1;
6903 bool FirstPass =
true;
6908 if(FirstPass && (TVPos2 != FirstRouteElementVecPos))
6936 ",FloatingLabelNextString" +
"," +
HeadCode);
6937 AnsiString RetStr =
"", LocationName =
"";
6941 throw Exception(
"Error - start entry in FloatingLabelNextString");
6981 else if(Ptr->
Command ==
"Fns")
6987 else if(Ptr->
Command ==
"F-nshs")
7018 RetStr =
"None, train terminated at " + Ptr->
LocationName;
7020 else if(Ptr->
Command ==
"Frh")
7022 RetStr =
"None, train terminated at " + Ptr->
LocationName;
7024 else if(Ptr->
Command ==
"Fer")
7026 AnsiString AllowedExits =
"";
7029 else if(Ptr->
Command ==
"Fjo")
7034 else if(Ptr->
Command ==
"jbo")
7039 else if(Ptr->
Command ==
"fsp")
7044 else if(Ptr->
Command ==
"rsp")
7049 else if(Ptr->
Command ==
"cdt")
7062 + AnsiString(RptNum) +
",CheckNewServiceDepartureTime," +
HeadCode);
7063 AnsiString DepTime =
"", EventTime =
"";
7064 bool CDTFlag =
false;
7068 if(AVI->Command ==
"cdt")
7073 if((AVI->Command ==
"fsp") || (AVI->Command ==
"rsp"))
7076 RetStr +=
"\nNew service splits at " + EventTime;
7080 if(AVI->Command ==
"jbo")
7083 RetStr +=
"\nNew service joined by " + AVI->OtherHeadCode +
" at " + EventTime;
7087 if((AVI->FormatType ==
TimeLoc) && (AVI->DepartureTime > TDateTime(-1)))
7092 RetStr +=
"\nNew service changes direction then departs at " + DepTime;
7096 RetStr +=
"\nNew service departs at " + DepTime;
7113 ",FloatingTimetableString" +
"," +
HeadCode);
7114 AnsiString RetStr =
"", PartStr =
"";
7116 bool SkipDep =
false, SkipDepActedOn =
false;
7122 throw Exception(
"Error - start entry in FloatingTimetableString");
7125 bool FirstPass =
true;
7138 AnsiString TrainLoc =
"";
7184 AnsiString TrainLoc =
"";
7220 else if(Ptr->
Command ==
"Fns")
7226 else if(Ptr->
Command ==
"F-nshs")
7259 else if(Ptr->
Command ==
"Frh")
7263 else if(Ptr->
Command ==
"Fer")
7265 AnsiString AllowedExits =
"";
7268 else if(Ptr->
Command ==
"Fjo")
7273 else if(Ptr->
Command ==
"jbo")
7278 else if(Ptr->
Command ==
"fsp")
7283 else if(Ptr->
Command ==
"rsp")
7288 else if(Ptr->
Command ==
"cdt")
7294 RetStr = RetStr +
'\n' + PartStr;
7308 SkipDepActedOn =
true;
7319 RetStr =
"Timetable finished";
7323 RetStr =
"No timetable";
7480 bool ForwardHeadCode;
7484 ForwardHeadCode =
true;
7489 ForwardHeadCode =
false;
7632 if(ColourNumber == 0)
7636 else if(ColourNumber == 1)
7640 else if(ColourNumber == 2)
7644 else if(ColourNumber == 3)
7648 else if(ColourNumber == 4)
7652 else if(ColourNumber == 5)
7656 else if(ColourNumber == 6)
7660 else if(ColourNumber == 7)
7664 else if(ColourNumber == 8)
7668 else if(ColourNumber == 9)
7672 else if(ColourNumber == 10)
7676 else if(ColourNumber == 11)
7680 else if(ColourNumber == 12)
7684 else if(ColourNumber == 13)
7688 else if(ColourNumber == 14)
7700 for(
int x = 0; x < 4; x++)
7707 for(
int x = 0; x < 4; x++)
7792 if((LocationAndMarker[1] !=
'*') && (LocationAndMarker.Length() > 6))
7795 AnsiString Location = LocationAndMarker.SubString(1, LocationAndMarker.Length() - 6);
7796 bool GiveMessagesFalse =
false;
7797 bool CheckLocationsExistInRailwayTrue =
true;
7804 AnsiString Marker = LocationAndMarker.SubString(LocationAndMarker.Length() - 5, 6);
7807 if(Marker[6] ==
'1')
8272 bool HideFlashingTrain =
true;
8275 Graphics::TBitmap *SmallTrainBitmap;
8316 HideFlashingTrain =
false;
8321 HideFlashingTrain =
false;
8326 HideFlashingTrain =
false;
8331 HideFlashingTrain =
false;
8336 HideFlashingTrain =
false;
8340 if((
LeadElement > -1) && (!HideFlashingTrain || Flash))
8344 if((
MidElement > -1) && (!HideFlashingTrain || Flash))
8368 for(
int y = 0; y < 3; y++)
8372 bool FoundFlag =
false;
8383 if(IMPair.first != IMPair.second)
8410 if((LocationName ==
"") && (
MidElement > -1))
8414 if((LocationName ==
"") && (
LagElement > -1))
8418 if(LocationName ==
"")
8420 throw Exception(
"Error - Location name not set in TrainAtLocation");
8431 for(
int x = 0; x < 4; x++)
8443 for(
int x = 0; x < 4; x++)
8460 AnsiString(LinkNumber) +
"," +
HeadCode);
8512 int DistanceToRedSignal = 0, DistanceToExit = -1;
8513 float TimeToAct = 0, LastTimeToExit =
TimeToExit;
8517 float MinsEarly = 0;
8518 TDateTime DepartureTime;
8519 TDateTime ArrivalTime;
8545 if(TempTTE < LastTimeToExit)
8573 if(TempTTE < LastTimeToExit)
8589 if(TempTTE < LastTimeToExit)
8611 if(TempTTE < LastTimeToExit)
8627 if(TempTTE < LastTimeToExit)
8665 float CurrentStopTime;
8666 float LaterStopTime;
8667 float RecoverableTime;
8675 if((DistanceToRedSignal == -1) && (DistanceToExit == -1))
8682 bool DistanceToRedSignalSet = (DistanceToRedSignal > -1);
8683 bool DistanceToExitSet = (DistanceToExit > -1);
8684 int GenericDistance = DistanceToRedSignal;
8685 if(DistanceToExitSet)
8687 GenericDistance = DistanceToExit;
8703 float TimeToSubtract, TotalStopTime;
8706 TimeToSubtract = RecoverableTime;
8749 if(CurrentStopTime > 0)
8751 TotalStopTime = CurrentStopTime + LaterStopTime;
8760 else if((MinsEarly > 0) && !
Stopped())
8762 TotalStopTime = LaterStopTime + MinsEarly;
8766 if(LaterStopTime == 0)
8768 TotalStopTime = CurrentStopTime;
8774 TotalStopTime = CurrentStopTime + LaterStopTime - TimeToSubtract;
8777 if(AvTrackSpeed < 30)
8781 int Speed = AvTrackSpeed;
8791 if(DistanceToRedSignalSet)
8793 TimeToAct = TotalStopTime + GenericDistance * 3.6 / 60 / Speed;
8803 TimeToExit = TotalStopTime + GenericDistance * 3.6 / 60 / Speed;
8826 if((NextEntryPos == 0) || (NextEntryPos == 2))
8953 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
8995 int IncrementalMinutes = 0;
8996 int IncrementalDigits = 0;
9004 throw Exception(
"Error - Repeat entry && less than two trains for Snt entry: " + TDEntry.
HeadCode);
9039 if(AVEntry0.
Command ==
"Snt-sh")
9044 int IncrementalMinutes = 0;
9045 int IncrementalDigits = 0;
9053 throw Exception(
"Error - Repeat entry && less than two trains for Snt-sh entry: " + TDEntry.
HeadCode);
9085 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
9154 AnsiString Loc =
"";
9155 bool ElementFound =
false;
9160 ElementFound =
true;
9165 ElementFound =
true;
9170 ElementFound =
true;
9199 else if(AVEntryPtr->
Command ==
"Fer")
9201 bool CorrectExit =
false;
9312 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
9330 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
9345 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
9356 bool TTrainController::AddTrain(
int Caller,
int RearPosition,
int FrontPosition, AnsiString HeadCode,
int StartSpeed,
int Mass,
double MaxRunningSpeed,
9357 double MaxBrakeRate,
double PowerAtRail, AnsiString ModeStr,
TTrainDataEntry *TrainDataEntryPtr,
int RepeatNumber,
int IncrementalMinutes,
9358 int IncrementalDigits,
int SignallerSpeed,
bool SignallerControl,
TActionEventType &EventType)
9360 LogEvent(AnsiString(Caller) +
",AddTrain," + AnsiString(RearPosition) +
"," + AnsiString(FrontPosition) +
"," + HeadCode +
"," + AnsiString(StartSpeed) +
9361 "," + AnsiString(Mass) +
"," + ModeStr);
9363 "," + HeadCode +
"," + AnsiString(StartSpeed) +
"," + AnsiString(Mass) +
"," + ModeStr);
9365 int RearExitPos = -1;
9367 for(
int x = 0; x < 4; x++)
9374 if(RearExitPos == -1)
9376 throw Exception(
"Error, RearExit == -1 in AddTrain");
9378 bool ReportFlag =
true;
9395 if(ModeStr ==
"Timetable")
9401 if(MaxRunningSpeed < 10)
9403 MaxRunningSpeed = 10;
9405 if(SignallerSpeed < 10)
9407 SignallerSpeed = 10;
9409 TTrain *NewTrain =
new TTrain(0, RearPosition, RearExitPos, HeadCode, StartSpeed, Mass, MaxRunningSpeed, MaxBrakeRate, PowerAtRail, TrainMode,
9410 TrainDataEntryPtr, RepeatNumber, IncrementalMinutes, IncrementalDigits, SignallerSpeed);
9417 if(SignallerControl)
9447 if(!SignallerControl)
9462 if(!SignallerControl)
9473 AnsiString Loc =
"";
9490 if(!SignallerControl)
9509 int RouteNumber = -1;
9510 bool SignalsSet =
false;
9517 int RouteStartPosition;
9521 if(FirstPair.first == RouteNumber)
9523 RouteStartPosition = FirstPair.second;
9525 else if(SecondPair.first == RouteNumber)
9527 RouteStartPosition = SecondPair.second;
9531 throw Exception(
"Error, RouteNumber not found in Route2MultiMap in 1st of 2 calls to SetAllRearwardsSignals in AddTrain");
9537 else if(RouteNumber > -1)
9557 int LinkedRouteNumber = -1;
9578 int RouteStartPosition;
9582 if(FirstPair.first == RouteNumber)
9584 RouteStartPosition = FirstPair.second;
9586 else if(SecondPair.first == RouteNumber)
9588 RouteStartPosition = SecondPair.second;
9592 throw Exception(
"Error, RouteNumber not found in Route2MultiMap in 2nd of 2 calls to SetAllRearwardsSignals in AddTrain");
9598 else if(RouteNumber > -1)
9618 int LinkedRouteNumber = -1;
9639 AnsiString(TrackVectorNumber));
9642 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
9651 throw Exception(
"Error, VecPos not set in EntryPos");
9653 if(
TrainVectorAt(2, VecPos).LeadElement == TrackVectorNumber)
9658 else if(
TrainVectorAt(4, VecPos).MidElement == TrackVectorNumber)
9663 else if(
TrainVectorAt(6, VecPos).LagElement == TrackVectorNumber)
9677 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
9685 throw Exception(
"Error - No Train identified in TrainVectorAtIdent with ID = " + AnsiString(TrainID));
9695 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
9725 AnsiString RetStr =
"", PartStr =
"";
9733 if((Ptr->Command !=
"") && (Ptr->Command[1] ==
'S'))
9741 if(Ptr->SignallerControl)
9743 RetStr =
"Train under signaller control";
9748 if(Ptr->ArrivalTime == Ptr->DepartureTime)
9759 else if((Ptr->FormatType ==
TimeLoc) && (Ptr->ArrivalTime != TDateTime(-1)))
9763 else if((Ptr->FormatType ==
TimeLoc) && (Ptr->ArrivalTime == TDateTime(-1)))
9767 else if(Ptr->FormatType ==
PassTime)
9771 else if(Ptr->Command ==
"Fns")
9777 else if(Ptr->Command ==
"F-nshs")
9780 Ptr->NonRepeatingShuttleLinkHeadCode +
" at " + Ptr->LocationName;
9787 else if((Ptr->Command ==
"Fns-sh") && (RepNum < (TTDEPtr->
NumberOfTrains - 1)))
9794 else if((Ptr->Command ==
"Fns-sh") && (RepNum >= (TTDEPtr->
NumberOfTrains - 1)))
9797 Ptr->NonRepeatingShuttleLinkHeadCode, +
" at " + Ptr->LocationName;
9800 else if((Ptr->Command ==
"Frh-sh") && (RepNum < (TTDEPtr->
NumberOfTrains - 1)))
9807 else if((Ptr->Command ==
"Frh-sh") && (RepNum >= (TTDEPtr->
NumberOfTrains - 1)))
9809 PartStr =
"Terminate at " + Ptr->LocationName;
9811 else if(Ptr->Command ==
"Frh")
9813 PartStr =
"Terminate at " + Ptr->LocationName;
9815 else if(Ptr->Command ==
"Fer")
9817 AnsiString AllowedExits;
9821 else if(Ptr->Command ==
"Fjo")
9824 Ptr->OtherHeadCode, RepNum, IncDig) +
" at " + Ptr->LocationName;
9826 else if(Ptr->Command ==
"jbo")
9829 (50, Ptr->OtherHeadCode, RepNum, IncDig) +
" at " + Ptr->LocationName;
9831 else if(Ptr->Command ==
"fsp")
9836 else if(Ptr->Command ==
"rsp")
9841 else if(Ptr->Command ==
"cdt")
9847 RetStr = RetStr +
'\n' + PartStr;
9855 while(Ptr < TTDEPtr->ActionVector.end() && (Count < 33) && ((Ptr->Command ==
"") || ((Ptr->Command !=
"") && (Ptr->Command[1] !=
'F'))));
9868 + AnsiString(RptNum) +
",ControllerCheckNewServiceDepartureTime," + TDEPtr->
HeadCode);
9869 AnsiString DepTime =
"", EventTime =
"";
9870 bool CDTFlag =
false;
9874 if(AVI->Command ==
"cdt")
9879 if((AVI->Command ==
"fsp") || (AVI->Command ==
"rsp"))
9882 RetStr +=
"\nNew service splits at " + EventTime;
9886 if(AVI->Command ==
"jbo")
9889 RetStr +=
"\nNew service joined by " + AVI->OtherHeadCode +
" at " + EventTime;
9893 if((AVI->FormatType ==
TimeLoc) && (AVI->DepartureTime > TDateTime(-1)))
9898 RetStr +=
"\nNew service changes direction then departs at " + DepTime;
9902 RetStr +=
"\nNew service departs at " + DepTime;
10062 ActiveTrackElementNameMapEntry.second = 0;
10068 std::ifstream TTBLFile(FileName, std::ios_base::binary);
10071 if(TTBLFile.is_open())
10073 char *TrainTimetableString =
new char[10000];
10075 bool EndOfFile =
false;
10078 TTBLFile.getline(TrainTimetableString, 10000,
'\0');
10080 if(TTBLFile.eof() && (TrainTimetableString[0] ==
'\0'))
10087 delete[] TrainTimetableString;
10091 AnsiString OneLine(TrainTimetableString);
10092 bool FinalCallFalse =
false;
10093 while((Count == 0) && !
ProcessOneTimetableLine(5, Count, OneLine, EndOfFile, FinalCallFalse, GiveMessages, CheckLocationsExistInRailway))
10097 TTBLFile.getline(TrainTimetableString, 10000,
'\0');
10098 if(TTBLFile.eof() && (TrainTimetableString[0] ==
'\0'))
10103 TimetableMessage(GiveMessages,
"Timetable invalid - unable to find a valid start time on its own line");
10105 delete[] TrainTimetableString;
10109 OneLine = AnsiString(TrainTimetableString);
10115 TTBLFile.getline(TrainTimetableString, 10000,
'\0');
10117 if(TTBLFile.eof() && (TrainTimetableString[0] ==
'\0'))
10127 OneLine = AnsiString(TrainTimetableString);
10129 if(OneLine.Length() > 9999)
10131 TimetableMessage(GiveMessages,
"Timetable contains a line that is too long - 10,000 or more characters!");
10133 delete[] TrainTimetableString;
10137 bool FinalCallFalse =
false;
10138 if(!
ProcessOneTimetableLine(6, Count, OneLine, EndOfFile, FinalCallFalse, GiveMessages, CheckLocationsExistInRailway))
10142 delete[] TrainTimetableString;
10146 if(EndOfFile && (Count < 2))
10149 TimetableMessage(GiveMessages,
"Timetable has too few or no relevant entries - must have a start time on its own line and at least one train");
10151 delete[] TrainTimetableString;
10157 delete[] TrainTimetableString;
10162 TimetableMessage(GiveMessages,
"Failed to open timetable file, make sure it's spelled correctly, it exists and isn't open in another application");
10173 bool CheckLocationsExistInRailway)
10298 AnsiString((
short)FinalCall) +
"," + AnsiString((
short)CheckLocationsExistInRailway));
10308 if(OneLine[1] !=
'*')
10310 int SCPos = OneLine.Pos(
';');
10321 bool AllCommas =
true;
10323 for(
int x = 1; x < OneLine.Length() + 1; x++)
10325 if(OneLine[x] !=
',')
10330 if(AllCommas || (OneLine ==
""))
10345 AnsiString First =
"", Second =
"", Third =
"", Fourth =
"";
10346 int RearStartOrRepeatMins = 0, FrontStartOrRepeatDigits = 0, NumberOfRepeats = 0;
10347 TDateTime EventTime(0), ArrivalTime(0), DepartureTime(0);
10348 TDateTime StartTime(0);
10350 bool Warning =
false;
10377 AnsiString TrainInfoStr =
"", HeadCode =
"", Description =
"";
10378 int StartSpeed = 0, MaxRunningSpeed = 0, Mass = 0;
10379 double MaxBrakeRate = 0;
10380 double PowerAtRail = 0;
10381 int SignallerSpeed = 0;
10382 if(OneLine[1] ==
'*')
10388 int Pos = OneLine.Pos(
',');
10391 int SubStringLength = 20;
10392 if(OneLine.Length() < 20)
10394 SubStringLength = OneLine.Length();
10396 TimetableMessage(GiveMessages,
"Error in timetable - entry incomplete: see '" + OneLine.SubString(1, SubStringLength) +
"'....");
10400 TrainInfoStr = OneLine.SubString(1, Pos - 1);
10401 if(!
SplitTrainInfo(0, TrainInfoStr, HeadCode, Description, StartSpeed, MaxRunningSpeed, Mass, MaxBrakeRate, PowerAtRail, SignallerSpeed,
10411 TempTrainDataEntry.
HeadCode = HeadCode;
10415 TempTrainDataEntry.
Mass = Mass;
10423 AnsiString NewRemainder = OneLine.SubString(Pos + 1, OneLine.Length() - Pos);
10426 while(NewRemainder[NewRemainder.Length()] ==
',')
10428 if(NewRemainder.Length() > 1)
10430 NewRemainder = NewRemainder.SubString(1, NewRemainder.Length() - 1);
10439 if(NewRemainder ==
"")
10441 TimetableMessage(GiveMessages,
"Error in timetable - no events following train: '" + OneLine +
"'");
10446 int CommaCount = 0;
10447 for(
int x = 1; x < NewRemainder.Length() + 1; x++)
10449 if(NewRemainder[x] ==
',')
10454 if(CommaCount == 0)
10456 if((NewRemainder.SubString(7, 3) !=
"Snt") || (NewRemainder[NewRemainder.Length()] !=
'S'))
10458 int SubStringLength = 20;
10459 if(OneLine.Length() < 20)
10461 SubStringLength = OneLine.Length();
10464 "Error in timetable - must have at least a start and a finish event for a train that is not started under signaller control - see line beginning: '" +
10465 OneLine.SubString(1, SubStringLength) +
"'....");
10470 AnsiString OneEntry =
"";
10475 bool FinishFlag =
false;
10476 for(
int x = 0; x < CommaCount + 1; x++)
10478 if((CommaCount == 0) || (x < CommaCount))
10483 if(CommaCount == 0)
10485 OneEntry = NewRemainder;
10490 Pos = NewRemainder.Pos(
',');
10491 OneEntry = NewRemainder.SubString(1, Pos - 1);
10492 NewRemainder = NewRemainder.SubString(Pos + 1, NewRemainder.Length() - Pos);
10498 RearStartOrRepeatMins = 0;
10499 FrontStartOrRepeatDigits = 0;
10500 NumberOfRepeats = 0;
10501 if(!
SplitEntry(0, OneEntry, GiveMessages, CheckLocationsExistInRailway, First, Second, Third, Fourth, RearStartOrRepeatMins,
10502 FrontStartOrRepeatDigits, FormatType, LocationType, SequenceType, ShuttleLinkType, ExitList, Warning))
10504 TimetableMessage(GiveMessages,
"Error in timetable - Event: '" + OneEntry +
"'");
10509 if(Warning && (Second ==
"Frh"))
10511 TimetableMessage(GiveMessages,
"Error in line - '" + OneEntry +
"': warnings cannot be given for 'Frh' events");
10515 if(Warning && (Second ==
"Fjo"))
10518 "': warnings cannot be given for 'Fjo' events, for a train join warning add a 'W' prefix to the 'jbo' event");
10524 if(SequenceType !=
Start)
10526 TimetableMessage(GiveMessages,
"Error in timetable - First event not a start event: '" + OneEntry +
"'");
10530 if((Second ==
"Snt") && (Fourth ==
'S') && (NewRemainder !=
""))
10532 if(NewRemainder[1] !=
'R')
10535 "Error in timetable - the only event that can follow a train created under signaller control is a repeat, see '" +
10541 if((Second ==
"Snt") || (Second ==
"Snt-sh"))
10545 if((HeadCode ==
"") || (Description ==
"") || (MaxRunningSpeed == 0) || (Mass == 0) || (MaxBrakeRate == 0))
10548 TimetableMessage(GiveMessages,
"Error in timetable - train information incomplete before 'Snt' or 'Snt-sh' start event: '" +
10554 if((Second ==
"Sfs") || (Second ==
"Sns") || (Second ==
"Sns-sh") || (Second ==
"Sns-fsh"))
10559 TimetableMessage(GiveMessages,
"Error in timetable - headcode missing before 'Sfs', 'Sns', 'Sns-sh' or 'Sns-fsh' start event: '" +
10564 if((StartSpeed != 0) || (MaxRunningSpeed != 0) || (Mass != 0) || (MaxBrakeRate != 0) || (PowerAtRail != 0))
10567 "Error in timetable - information additional to a headcode & optional description given before 'Sfs', 'Sns', 'Sns-sh' or 'Sns-fsh' start event: '" +
10574 if(SequenceType ==
Finish)
10583 TDateTime TempTime;
10589 ActionVectorEntry.
Warning = Warning;
10605 ActionVectorEntry.
Command = Second;
10620 else if(FormatType ==
TimeCmd)
10626 ActionVectorEntry.
Command = Second;
10634 ActionVectorEntry.
Command = Second;
10635 ActionVectorEntry.
ExitList = ExitList;
10643 ActionVectorEntry.
Command = Second;
10657 ActionVectorEntry.
Command = Second;
10668 ActionVectorEntry.
Command = Second;
10678 ActionVectorEntry.
Command = Second;
10687 ActionVectorEntry.
Command = Second;
10696 ActionVectorEntry.
Command = Second;
10702 ActionVectorEntry.
Command = Second;
10704 TempTrainDataEntry.
ActionVector.push_back(ActionVectorEntry);
10709 OneEntry = NewRemainder;
10714 RearStartOrRepeatMins = 0;
10715 FrontStartOrRepeatDigits = 0;
10716 NumberOfRepeats = 0;
10717 if((FinishFlag) && (OneEntry[1] !=
'R'))
10720 TimetableMessage(GiveMessages,
"Error in timetable - Last event = '" + OneEntry +
"'. An earlier finish event has been found with something other than a repeat following it - only a repeat can follow a finish event.");
10724 if(OneEntry[1] !=
'R')
10726 if(!
SplitEntry(1, OneEntry, GiveMessages, CheckLocationsExistInRailway, First, Second, Third, Fourth, RearStartOrRepeatMins,
10727 FrontStartOrRepeatDigits, FormatType, LocationType, SequenceType, ShuttleLinkType, ExitList, Warning))
10729 TimetableMessage(GiveMessages,
"Error in timetable - Event: '" + OneEntry +
"'");
10733 if(SequenceType !=
Finish)
10735 TimetableMessage(GiveMessages,
"Error in timetable - last event should be a finish: '" + OneEntry +
"'");
10742 TDateTime TempTime;
10748 ActionVectorEntry.
Warning = Warning;
10755 ActionVectorEntry.
Command = Second;
10763 ActionVectorEntry.
Command = Second;
10772 ActionVectorEntry.
Command = Second;
10781 ActionVectorEntry.
Command = Second;
10791 ActionVectorEntry.
Command = Second;
10792 ActionVectorEntry.
ExitList = ExitList;
10796 ActionVectorEntry.
Command = Second;
10798 TempTrainDataEntry.
ActionVector.push_back(ActionVectorEntry);
10803 if(!
SplitRepeat(0, OneEntry, RearStartOrRepeatMins, FrontStartOrRepeatDigits, NumberOfRepeats, GiveMessages))
10819 TempTrainDataEntry.
ActionVector.push_back(ActionVectorEntry);
10838 if((HeadCode[HeadCode.Length() - 1] <
'0') || (HeadCode[HeadCode.Length() - 1] >
'9'))
10843 if((HeadCode[HeadCode.Length()] <
'0') || (HeadCode[HeadCode.Length()] >
'9'))
10858 if(TimeStr.Length() < 5)
10863 if((TimeStr[1] <
'0') || (TimeStr[1] >
'9'))
10868 if((TimeStr[2] <
'0') || (TimeStr[2] >
'9'))
10873 if(TimeStr[3] !=
':')
10878 if((TimeStr[4] <
'0') || (TimeStr[4] >
'5'))
10883 if((TimeStr[5] <
'0') || (TimeStr[5] >
'9'))
10888 while(TimeStr.Length() > 5)
10890 TimeStr = TimeStr.SubString(1, TimeStr.Length() - 1);
10892 double WholeHours = (AnsiString(TimeStr[1]) + AnsiString(TimeStr[2])).ToDouble();
10893 double FracHour = ((AnsiString(TimeStr[4]) + AnsiString(TimeStr[5])).ToDouble()) / 60.0;
10895 if((WholeHours + FracHour) >= 95.98334)
10900 Time = TDateTime((WholeHours + FracHour) / 24);
10907 bool TTrainController::SplitEntry(
int Caller, AnsiString OneEntry,
bool GiveMessages,
bool CheckLocationsExistInRailway, AnsiString &First, AnsiString &Second,
10908 AnsiString &Third, AnsiString &Fourth,
int &RearStartOrRepeatMins,
int &FrontStartOrRepeatDigits,
TTimetableFormatType &FormatType,
10917 TDateTime TempTime;
10919 if(OneEntry.Length() > 0)
10921 if(OneEntry[1] ==
'W')
10924 OneEntry = OneEntry.SubString(2, OneEntry.Length() - 1);
10928 if(OneEntry ==
"Frh")
10938 if(OneEntry.Length() < 7)
10943 int Pos = OneEntry.Pos(
';');
10951 First = OneEntry.SubString(1, 5);
10957 AnsiString Remainder = OneEntry.SubString(Pos + 1, OneEntry.Length() - Pos);
10959 if((Remainder[1] >=
'0') && (Remainder[1] <=
'9'))
10962 if(Remainder.Length() < 7)
10967 Pos = Remainder.Pos(
';');
10974 Second = Remainder.SubString(1, 5);
10980 Third = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
10993 Pos = Remainder.Pos(
';');
10996 Second = Remainder;
10997 if(Second ==
"cdt")
11022 if((Pos != 4) && (Pos != 7) && (Pos != 8))
11028 Second = Remainder.SubString(1, Pos - 1);
11030 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11032 Pos = Remainder.Pos(
';');
11039 Third = Remainder.SubString(1, Pos - 1);
11040 Fourth = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11042 if((Second ==
"Snt") || (Second ==
"Snt-sh"))
11045 int SpacePos = Third.Pos(
' ');
11051 AnsiString RearStartStr = Third.SubString(1, SpacePos - 1);
11052 AnsiString FrontStartStr = Third.SubString(SpacePos + 1, Third.Length() - SpacePos);
11054 if(CheckLocationsExistInRailway)
11064 if(Second ==
"Snt")
11067 SequenceType =
Start;
11076 SequenceType =
Start;
11087 if(Second ==
"Sns-sh")
11091 SequenceType =
Start;
11106 if(Second ==
"F-nshs")
11120 if(Second ==
"Sns-fsh")
11124 SequenceType =
Start;
11134 if(Second ==
"Fns-sh")
11154 if(Second ==
"pas")
11169 if(Second ==
"Fer")
11176 if(CheckLocationsExistInRailway)
11188 if((Second !=
"Fns") && (Second !=
"Fjo") && (Second !=
"jbo") && (Second !=
"fsp") && (Second !=
"rsp") && (Second !=
"Sfs") && (Second !=
"Sns") &&
11189 (Second !=
"Frh-sh"))
11201 if(Second ==
"Frh-sh")
11209 if((Second ==
"Fns") || (Second ==
"Fjo") || (Second ==
"Frh-sh"))
11213 if((Second ==
"jbo") || (Second ==
"fsp") || (Second ==
"rsp"))
11217 if((Second ==
"Sfs") || (Second ==
"Sns"))
11219 SequenceType =
Start;
11237 if((LocStr[1] >=
'0') && (LocStr[1] <=
'9'))
11242 for(
int x = 1; x < LocStr.Length() + 1; x++)
11244 if(LocStr[x] <
' ')
11249 if(LocStr[x] >
'z')
11256 if(CheckLocationsExistInRailway)
11261 "' appears in the timetable but is not a valid name. To be valid the name must be a stopping location and apply to one or more platforms " +
11262 "(not concourses on their own), or to track at a blue non-station named location. BUT NOTE THAT trains can't stop at continuations so a name " +
11263 "that includes a continuation will not be valid.");
11281 if((HeadCode.Length() < 4) || (HeadCode.Length() > 8))
11284 "', length must be between 4 and 8 characters, and last 4 must be a legitimate headcode. This error can also be caused by omitting a service reference after Sns, Snt-sh, Sns-sh, Fns, Fns-sh or Frh-sh");
11289 for(
int x = 1; x < (HeadCode.Length() + 1); x++)
11291 if((HeadCode[x] <
' ') || (HeadCode[x] >
'~'))
11293 TimetableMessage(GiveMessages,
"Non-printable character in headcode '" + HeadCode +
"'");
11299 for(
int x = 3; x >= 0; x--)
11301 if(((HeadCode[HeadCode.Length() - x] <
'A') || (HeadCode[HeadCode.Length() - x] >
'Z')) && ((HeadCode[HeadCode.Length() - x] <
'a') ||
11302 (HeadCode[HeadCode.Length() - x] >
'z')) && ((HeadCode[HeadCode.Length() - x] <
'0') || (HeadCode[HeadCode.Length() - x] >
'9')))
11304 TimetableMessage(GiveMessages,
"Headcode error in '" + HeadCode +
"', headcode must consist of letters and digits only");
11320 AnsiString CurrentID =
"";
11322 if(IDSet.Length() == 0)
11324 TimetableMessage(GiveMessages,
"Must have at least one exit element ID following 'Fer'");
11328 for(
int x = 1; x <= IDSet.Length(); x++)
11331 if(((C <
'0') || (C >
'9')) && (C !=
' ') && (C !=
'N') && (C !=
'-'))
11333 TimetableMessage(GiveMessages,
"Illegal character in the set of element IDs following 'Fer' in '" + IDSet +
"'");
11338 int Pos = IDSet.Pos(
' ');
11349 CurrentID = IDSet.SubString(1, Pos - 1);
11350 IDSet = IDSet.SubString(Pos + 1, IDSet.Length() - Pos);
11362 TimetableMessage(GiveMessages,
"The element ID '" + CurrentID +
"' following 'Fer' is not an exit");
11369 if(!ExitList.empty())
11371 for(
TNumListIterator ELIT = ExitList.begin(); ELIT != ExitList.end(); ELIT++)
11373 if(*ELIT == VecPos)
11375 TimetableMessage(GiveMessages,
"The element ID '" + CurrentID +
"' following 'Fer' duplicates an earlier element");
11382 ExitList.push_back(VecPos);
11392 Pos = IDSet.Pos(
' ');
11399 int &Mass,
double &MaxBrakeRate,
double &PowerAtRail,
int &SignallerSpeed,
bool GiveMessages)
11406 AnsiString Remainder =
"";
11407 int SemiColonCount = 0;
11409 for(
int x = 1; x < TrainInfoStr.Length() + 1; x++)
11411 if(TrainInfoStr[x] ==
';')
11416 if((SemiColonCount != 6) && (SemiColonCount != 7) && (SemiColonCount != 1) && (SemiColonCount != 0))
11418 TimetableMessage(GiveMessages,
"Error in train information in '" + TrainInfoStr +
11419 "'. Should be headcode + optional description for a continuing service;" +
11420 " or headcode, description, start speed, max running speed, mass, brake force, power (and optional signaller max. speed) for a new service");
11424 if(SemiColonCount == 0)
11426 HeadCode = TrainInfoStr;
11435 if(SemiColonCount == 1)
11437 Pos = TrainInfoStr.Pos(
';');
11438 HeadCode = TrainInfoStr.SubString(1, Pos - 1);
11439 Description = TrainInfoStr.SubString(Pos + 1, TrainInfoStr.Length() - Pos);
11445 if(Description ==
"")
11447 TimetableMessage(GiveMessages,
"Train description missing in '" + TrainInfoStr +
"'");
11451 if(Description.Length() > 60)
11453 TimetableMessage(GiveMessages,
"Train description too long, limit of 60 characters '" + TrainInfoStr +
"'");
11457 for(
int x = 1; x < Description.Length() + 1; x++)
11459 if((Description[x] <
' ') || (Description[x] >
'~'))
11461 TimetableMessage(GiveMessages,
"Train description contains invalid characters in '" + TrainInfoStr +
"'");
11470 Pos = TrainInfoStr.Pos(
';');
11471 HeadCode = TrainInfoStr.SubString(1, Pos - 1);
11472 Remainder = TrainInfoStr.SubString(Pos + 1, TrainInfoStr.Length() - Pos);
11478 Pos = Remainder.Pos(
';');
11479 Description = Remainder.SubString(1, Pos - 1);
11480 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11481 if(Description ==
"")
11483 TimetableMessage(GiveMessages,
"Train description missing in '" + TrainInfoStr +
"'");
11487 if(Description.Length() > 60)
11489 TimetableMessage(GiveMessages,
"Train description too long, limit of 60 characters '" + TrainInfoStr +
"'");
11493 for(
int x = 1; x < Description.Length() + 1; x++)
11495 if((Description[x] <
' ') || (Description[x] > 126))
11497 TimetableMessage(GiveMessages,
"Train description contains invalid characters in '" + TrainInfoStr +
"'");
11502 Pos = Remainder.Pos(
';');
11503 AnsiString StartSpeedStr = Remainder.SubString(1, Pos - 1);
11505 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11506 if(StartSpeedStr ==
"")
11508 TimetableMessage(GiveMessages,
"Train starting speed missing in '" + TrainInfoStr +
"'");
11512 for(
int x = 1; x < StartSpeedStr.Length() + 1; x++)
11514 if((StartSpeedStr[x] <
'0') || (StartSpeedStr[x] >
'9'))
11516 TimetableMessage(GiveMessages,
"Train start speed contains invalid characters in '" + TrainInfoStr +
"'");
11521 StartSpeed = StartSpeedStr.ToInt();
11527 TimetableMessage(GiveMessages,
"Train starting speed > 400km/h in '" + TrainInfoStr +
"'. Setting it to 400km/h");
11531 Pos = Remainder.Pos(
';');
11532 AnsiString MaxRunningSpeedStr = Remainder.SubString(1, Pos - 1);
11534 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11535 if(MaxRunningSpeedStr ==
"")
11537 TimetableMessage(GiveMessages,
"Train maximum running speed missing in '" + TrainInfoStr +
"'");
11541 for(
int x = 1; x < MaxRunningSpeedStr.Length() + 1; x++)
11543 if((MaxRunningSpeedStr[x] <
'0') || (MaxRunningSpeedStr[x] >
'9'))
11545 TimetableMessage(GiveMessages,
"Train maximum running speed contains invalid characters in '" + TrainInfoStr +
"'");
11550 MaxRunningSpeed = MaxRunningSpeedStr.ToInt();
11556 TimetableMessage(GiveMessages,
"Train maximum running speed > 400km/h in '" + TrainInfoStr +
"'. Setting it to 400km/h");
11560 if(MaxRunningSpeed < 10)
11563 MaxRunningSpeed = 10;
11566 TimetableMessage(GiveMessages,
"Train maximum running speed can't be less than 10km/h in '" + TrainInfoStr +
"', it will be set to 10km/h");
11570 Pos = Remainder.Pos(
';');
11571 AnsiString MassStr = Remainder.SubString(1, Pos - 1);
11573 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11576 TimetableMessage(GiveMessages,
"Train mass missing in '" + TrainInfoStr +
"'");
11580 for(
int x = 1; x < MassStr.Length() + 1; x++)
11582 if((MassStr[x] <
'0') || (MassStr[x] >
'9'))
11584 TimetableMessage(GiveMessages,
"Train mass contains invalid characters in '" + TrainInfoStr +
"'");
11589 Mass = MassStr.ToInt() * 1000;
11595 TimetableMessage(GiveMessages,
"Train mass > 10,000 tonnes in '" + TrainInfoStr +
"'. Setting it to 10,000 tonnes");
11601 TimetableMessage(GiveMessages,
"Train mass zero in '" + TrainInfoStr +
"'");
11605 Pos = Remainder.Pos(
';');
11606 AnsiString MaxBrakeForceStr = Remainder.SubString(1, Pos - 1);
11608 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11609 if(MaxBrakeForceStr ==
"")
11611 TimetableMessage(GiveMessages,
"Train braking force missing in '" + TrainInfoStr +
"'");
11615 for(
int x = 1; x < (MaxBrakeForceStr.Length() + 1); x++)
11617 if((MaxBrakeForceStr[x] !=
'.') && ((MaxBrakeForceStr[x] <
'0') || (MaxBrakeForceStr[x] >
'9')))
11619 TimetableMessage(GiveMessages,
"Train braking force contains invalid characters in '" + TrainInfoStr +
"'");
11624 double MaxBrakeForce = MaxBrakeForceStr.ToDouble() * 1000;
11627 if((MaxBrakeForce / Mass) > 1)
11629 MaxBrakeForce = Mass;
11632 TimetableMessage(GiveMessages,
"Train braking force too high in '" + TrainInfoStr +
"'. Setting it to the same as the train mass");
11636 if((MaxBrakeForce / Mass) < 0.01)
11638 MaxBrakeForce = Mass * 0.01;
11641 TimetableMessage(GiveMessages,
"Train braking force too low in '" + TrainInfoStr +
"'. Setting it to 1% of the train mass");
11646 MaxBrakeRate = MaxBrakeForce / Mass * 9.81;
11648 AnsiString GrossPowerStr =
"", SignallerSpeedStr =
"";
11650 if(SemiColonCount == 6)
11652 GrossPowerStr = Remainder;
11653 SignallerSpeedStr =
"30";
11657 Pos = Remainder.Pos(
';');
11658 GrossPowerStr = Remainder.SubString(1, Pos - 1);
11659 SignallerSpeedStr = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11662 if(GrossPowerStr ==
"")
11664 TimetableMessage(GiveMessages,
"Train power missing in '" + TrainInfoStr +
"'");
11668 for(
int x = 1; x < GrossPowerStr.Length() + 1; x++)
11670 if((GrossPowerStr[x] <
'0') || (GrossPowerStr[x] >
'9'))
11672 TimetableMessage(GiveMessages,
"Train power contains invalid characters in '" + TrainInfoStr +
"'");
11678 double GrossPower = GrossPowerStr.ToInt() * 1000;
11685 TimetableMessage(GiveMessages,
"Train power > 100,000kW in '" + TrainInfoStr +
"'. Setting it to 100,000kW");
11689 else if(GrossPower == 0)
11694 else if((GrossPower > 0) && (GrossPower < 10000))
11697 GrossPower = 10000;
11699 PowerAtRail = GrossPower * 0.8;
11703 if(SignallerSpeedStr ==
"")
11705 TimetableMessage(GiveMessages,
"Signaller speed not set in '" + TrainInfoStr +
"', either set a value or remove the extra semicolon");
11709 for(
int x = 1; x < SignallerSpeedStr.Length() + 1; x++)
11711 if((SignallerSpeedStr[x] <
'0') || (SignallerSpeedStr[x] >
'9'))
11713 TimetableMessage(GiveMessages,
"Signaller speed contains invalid characters in '" + TrainInfoStr +
"'");
11718 SignallerSpeed = SignallerSpeedStr.ToInt();
11724 TimetableMessage(GiveMessages,
"Signaller speed > 400km/h in '" + TrainInfoStr +
"'. Setting it to 400km/h");
11728 if(SignallerSpeed < 10)
11731 SignallerSpeed = 10;
11734 TimetableMessage(GiveMessages,
"Signaller speed can't be less than 10km/h in '" + TrainInfoStr +
"', it will be set to 10km/h");
11752 if(OneEntry.Length() < 7)
11754 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - should be 'R;m;d;n'");
11758 int SemiColonCount = 0;
11760 for(
int x = 1; x < OneEntry.Length() + 1; x++)
11762 if(OneEntry[x] ==
';')
11767 if(SemiColonCount != 3)
11769 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - should be 'R;m;d;n'");
11773 if((OneEntry[1] !=
'R') || (OneEntry[2] !=
';'))
11775 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - should be 'R;m;d;n'");
11779 AnsiString Remainder = OneEntry.SubString(3, OneEntry.Length() - 2);
11784 Pos = Remainder.Pos(
';');
11785 AnsiString MinutesStr = Remainder.SubString(1, Pos - 1);
11787 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11788 if(MinutesStr ==
"")
11790 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - minute increment segment missing");
11794 if(MinutesStr.Length() > 3)
11797 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - minute value too high, maximum value is 999");
11801 for(
int x = 1; x < MinutesStr.Length() + 1; x++)
11803 if((MinutesStr[x] <
'0') || (MinutesStr[x] >
'9'))
11805 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - non-digit character in minute increment segment");
11810 RearStartOrRepeatMins = MinutesStr.ToInt();
11811 if(RearStartOrRepeatMins == 0)
11813 TimetableMessage(GiveMessages,
"Repeat minute increment is zero in: '" + OneEntry +
"' - can't have a zero value");
11817 Pos = Remainder.Pos(
';');
11818 AnsiString DigitsStr = Remainder.SubString(1, Pos - 1);
11820 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
11821 if(DigitsStr ==
"")
11823 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - headcode increment segment missing");
11827 for(
int x = 1; x < DigitsStr.Length() + 1; x++)
11829 if((DigitsStr[x] <
'0') || (DigitsStr[x] >
'9'))
11831 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - non-digit character in headcode increment segment");
11836 if(DigitsStr.Length() > 2)
11838 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - maximum number of digits for headcode increment is 2");
11842 FrontStartOrRepeatDigits = DigitsStr.ToInt();
11856 "' - a repeating service with incrementing digits must have digits as its last two headcode characters");
11860 AnsiString NumberStr = Remainder;
11862 if(NumberStr ==
"")
11864 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - number of repeats missing");
11868 if(NumberStr.Length() > 4)
11871 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - repeat value too high, no timetabled event can exceed 95 hours & 59 minutes");
11875 for(
int x = 1; x < NumberStr.Length() + 1; x++)
11877 if((NumberStr[x] <
'0') || (NumberStr[x] >
'9'))
11880 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - non-digit character in number of repeats");
11885 NumberOfRepeats = NumberStr.ToInt();
11886 if(NumberOfRepeats == 0)
11888 TimetableMessage(GiveMessages,
"Number of repeats is zero in: '" + OneEntry +
"' - if no repeats are needed the repeat should be omitted");
12060 SecondPassMessage(GiveMessages,
"Error in timetable - there appear to be no train services in the timetable, it must contain at least one");
12079 TwoLocationFlag =
false;
12085 SecondPassMessage(GiveMessages,
"Error in timetable - the following service has no listed events, there must be at least one: " + TDEntry.
HeadCode);
12099 SecondPassMessage(GiveMessages,
"Error in timetable - service must have a start event and at least one other for: " + TDEntry.
HeadCode);
12115 "Error in timetable - a signaller control service can have no more than one item (a repeat) after the start event, see: " +
12127 "Error in timetable - a signaller control service cannot have any other than a repeat after the start event, see: " + TDEntry.
HeadCode);
12154 SecondPassMessage(GiveMessages,
"Error in timetable - finish events Fns-sh and Frh-sh not permitted immediately after an Snt entry for: " +
12165 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12170 SecondPassMessage(GiveMessages,
"Error in timetable - a start event is present that is not the first event for: " + TDEntry.
HeadCode);
12180 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12185 SecondPassMessage(GiveMessages,
"Error in timetable - a repeat is present that is not the last item for: " + TDEntry.
HeadCode);
12195 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12206 SecondPassMessage(GiveMessages,
"Error in timetable - the last item must be either a finish event or a repeat for: " + TDEntry.
HeadCode);
12216 SecondPassMessage(GiveMessages,
"Error in timetable - the last event before the repeat must be a finish for: " + TDEntry.
HeadCode);
12228 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12235 SecondPassMessage(GiveMessages,
"Error in timetable - a finish event must be either the last or last but one for: " + TDEntry.
HeadCode);
12244 SecondPassMessage(GiveMessages,
"Error in timetable - the only event that can follow a finish event is a repeat for: " +
12264 if((AVEntry0.
Command ==
"Snt") || (AVEntry0.
Command ==
"Snt-sh"))
12266 AnsiString LocationName =
"";
12282 SecondPassMessage(GiveMessages,
"Error in timetable - stopped 'Snt' or 'Snt-sh' followed by an illegal event for: " +
12283 TDEntry.
HeadCode +
". The event isn't valid for a stationary train.");
12292 SecondPassMessage(GiveMessages,
"Error in timetable - 'Snt' or 'Snt-sh' event at stop location but start speed not zero for: " +
12301 if(AVEntry0.
Command ==
"Snt-sh")
12315 SecondPassMessage(GiveMessages,
"Error in timetable - unlocated 'Snt' not followed by 'Fer', 'pas' or an arrival for: " +
12331 SecondPassMessage(GiveMessages,
"Error in timetable - 'Sfs', 'Sns', 'Sns-sh' or 'Sns-fsh' followed by an illegal event for: " +
12332 TDEntry.
HeadCode +
". The event isn't valid for a stationary train.");
12343 bool FoundFlag =
false;
12349 for(
unsigned int y = 1; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12361 SecondPassMessage(GiveMessages,
"Error in timetable - no location departure following an 'Sfs', 'Sns', 'Sns-sh'or 'Sns-fsh' event for: " +
12374 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12383 ": an event should have had a location name associated with it but it could not be found");
12389 for(
unsigned int z = y + 1; z <
TrainDataVector.at(x).ActionVector.size(); z++)
12411 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12421 SecondPassMessage(GiveMessages,
"Error in timetable - only a repeat can follow a finish entry for: " + TDEntry.
HeadCode);
12428 if(AVEntry.
Command ==
"F-nshs")
12433 SecondPassMessage(GiveMessages,
"Error in timetable - F-nshs (shuttle link) must be the last event for: " + TDEntry.
HeadCode);
12461 SecondPassMessage(GiveMessages,
"Error in timetable - a jbo event is followed by an illegal event for: " + TDEntry.
HeadCode +
12462 ". The event isn't valid for a stationary train.");
12472 SecondPassMessage(GiveMessages,
"Error in timetable - a train split can't be the last event for: " + TDEntry.
HeadCode);
12480 SecondPassMessage(GiveMessages,
"Error in timetable - a train split is followed by an illegal event for: " + TDEntry.
HeadCode +
12481 ". The event isn't valid for a stationary train.");
12499 SecondPassMessage(GiveMessages,
"Error in timetable - a 'cdt' is followed by an illegal event for: " + TDEntry.
HeadCode +
12500 ". The event isn't valid for a stationary train.");
12510 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival and departure can't be the last event for: " + TDEntry.
HeadCode);
12518 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival and departure is followed by an illegal event for: " +
12519 TDEntry.
HeadCode +
". The event isn't valid for a moving train.");
12537 SecondPassMessage(GiveMessages,
"Error in timetable - a pass time is followed by an illegal event for: " + TDEntry.
HeadCode +
12538 ". The event isn't valid for a moving train.");
12560 bool LastEntryIsAnArrival =
false;
12567 LastEntryIsAnArrival =
false;
12568 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12575 throw Exception(
"Timetable error, TimeLoc times not as initially set for " + TDEntry.
HeadCode);
12577 if(LastEntryIsAnArrival)
12581 LastEntryIsAnArrival =
false;
12587 LastEntryIsAnArrival =
true;
12594 LastEntryIsAnArrival =
true;
12595 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12602 throw Exception(
"Timetable error, TimeLoc times not as initially set for " + TDEntry.
HeadCode);
12604 if(LastEntryIsAnArrival)
12608 LastEntryIsAnArrival =
false;
12614 LastEntryIsAnArrival =
true;
12624 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12632 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival can't be the last event for: " + TDEntry.
HeadCode);
12640 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival is followed by an illegal event for: " + TDEntry.
HeadCode +
12641 ". The event isn't valid for a stationary train.");
12652 SecondPassMessage(GiveMessages,
"Error in timetable - a timed departure can't be the last event for: " + TDEntry.
HeadCode);
12660 SecondPassMessage(GiveMessages,
"Error in timetable - a timed departure is followed by an illegal event for: " + TDEntry.
HeadCode +
12661 ". The event isn't valid for a moving train.");
12675 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12682 throw Exception(
"Timetable error, TimeLoc entry has EventTime not -1 for " + TDEntry.
HeadCode);
12686 throw Exception(
"Timetable error, TimeLoc entry has neither arrival nor departure time set for " + TDEntry.
HeadCode);
12693 throw Exception(
"Timetable error, TimeTimeLoc entry has EventTime not -1 for " + TDEntry.
HeadCode);
12697 throw Exception(
"Timetable error, TimeTimeLoc entry has either arrival or departure time not set for " + TDEntry.
HeadCode);
12706 throw Exception(
"Timetable error, Cmd or PassTime entry has EventTime not set for " + TDEntry.
HeadCode);
12710 throw Exception(
"Timetable error, Cmd or PassTime entry has either arrival or departure time set for " + TDEntry.
HeadCode);
12717 throw Exception(
"Timetable error, Repeat entry has a time set for " + TDEntry.
HeadCode);
12728 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12743 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival and departure has a later arrival than departure time for: " +
12751 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival and departure has too early an arrival time for: " +
12766 SecondPassMessage(GiveMessages,
"Error in timetable - a timed location event has a time that is too early for: " + TDEntry.
HeadCode);
12778 SecondPassMessage(GiveMessages,
"Error in timetable - a timed location event has a time that is too early for: " + TDEntry.
HeadCode);
12790 SecondPassMessage(GiveMessages,
"Error in timetable - a train event has a time that is set too early for: " + TDEntry.
HeadCode +
12791 ", may be before timetable start time");
12802 AnsiString LastLocationName =
"";
12806 bool LastEntryIsAnArrival =
false;
12811 LastEntryIsAnArrival =
false;
12812 LastLocationName =
TrainDataVector.at(x).ActionVector.at(0).LocationName;
12813 if(LastLocationName !=
"")
12815 throw Exception(
"Timetable error, moving Snt entry has LocationName set for " + TDEntry.
HeadCode);
12817 for(
unsigned int y = 1; y <
TrainDataVector.at(x).ActionVector.size();
12830 SecondPassMessage(GiveMessages,
"Error in timetable - a location event is inconsistent for: " + TDEntry.
HeadCode +
" && " +
12842 SecondPassMessage(GiveMessages,
"Error in timetable - a location event is inconsistent for: " + TDEntry.
HeadCode +
" && " +
12855 TwoLocationFlag =
true;
12860 LastEntryIsAnArrival =
false;
12864 if(LastEntryIsAnArrival && (AVEntry.
LocationName != LastLocationName))
12867 "Error in timetable - a location event for a timed departure is different from the arrival location for: " + TDEntry.
HeadCode);
12872 else if(!LastEntryIsAnArrival && (AVEntry.
LocationName == LastLocationName))
12875 "Error in timetable - a location event for a timed arrival is the same as the earlier departure location for: " + TDEntry.
HeadCode);
12881 LastEntryIsAnArrival = !LastEntryIsAnArrival;
12887 LastEntryIsAnArrival =
true;
12888 LastLocationName =
TrainDataVector.at(x).ActionVector.at(0).LocationName;
12889 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12901 SecondPassMessage(GiveMessages,
"Error in timetable - a location event is inconsistent for: " + TDEntry.
HeadCode +
" && " +
12913 SecondPassMessage(GiveMessages,
"Error in timetable - a location event is inconsistent for: " + TDEntry.
HeadCode +
" && " +
12926 TwoLocationFlag =
true;
12931 LastEntryIsAnArrival =
false;
12935 if(LastEntryIsAnArrival && (AVEntry.
LocationName != LastLocationName))
12938 "Error in timetable - a location event for a timed departure is different from the arrival location for: " + TDEntry.
HeadCode);
12946 "A location event for a timed arrival is the same as the earlier departure location for: " + TDEntry.
HeadCode +
". Please correct if this is an error.\n\nThis warning will not be shown again.");
12953 LastEntryIsAnArrival = !LastEntryIsAnArrival;
12961 AnsiString LocationNameToBeChecked =
"";
12966 unsigned int y = 0;
12980 LocationNameToBeChecked = TDEntry.
ActionVector.at(y).LocationName;
12981 for(
unsigned int z = y; z < TDEntry.
ActionVector.size(); z++)
12999 for(
unsigned int a = z; a < TDEntry.
ActionVector.size(); a++)
13008 TwoLocationFlag =
true;
13019 if(TwoLocationFlag)
13029 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13034 throw Exception(
"Error, non- 'Snt', 'Fer' or Repeat entry doesn't have a location name set for " + TDEntry.
HeadCode);
13036 AnsiString LocName =
"";
13042 throw Exception(
"Error, 'Snt' entry at a stop location doesn't have a location name set for " + TDEntry.
HeadCode);
13049 throw Exception(
"Error, 'Snt' unlocated entry has a location name set for " + TDEntry.
HeadCode);
13072 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13097 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13119 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13141 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13160 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13163 if((AVEntry.
Command ==
"Sns-sh") || (AVEntry.
Command ==
"Snt-sh"))
13178 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13183 throw Exception(
"Error - timetable ActionVector entry no. " + AnsiString(y) +
" has FormatType unset for: " + TDEntry.
HeadCode);
13187 throw Exception(
"Error - timetable ActionVector entry no. " + AnsiString(y) +
" has SequenceType unset for: " + TDEntry.
HeadCode);
13191 throw Exception(
"Error - timetable ActionVector entry no. " + AnsiString(y) +
" has LocationType unset for: " + TDEntry.
HeadCode);
13195 throw Exception(
"Error - timetable ActionVector entry no. " + AnsiString(y) +
" has ShuttleLinkType unset for: " + TDEntry.
HeadCode);
13234 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13236 AnsiString LocName =
TrainDataVector.at(x).ActionVector.at(y).LocationName;
13242 SecondPassMessage(GiveMessages,
"Error in timetable - continuation names (" + LocName +
") must not be included, see service " + HC);
13255 int IncMinutes = 0;
13265 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13271 SecondPassMessage(GiveMessages,
"Error in timetable - a repeat time exceeds 95h 59m, see service " + HC);
13277 if((
double)
TrainDataVector.at(x).ActionVector.at(y).ArrivalTime > -1)
13282 SecondPassMessage(GiveMessages,
"Error in timetable - a repeat entry time exceeds 95h 59m, see service " + HC);
13288 if((
double)
TrainDataVector.at(x).ActionVector.at(y).DepartureTime > -1)
13293 SecondPassMessage(GiveMessages,
"Error in timetable - a repeat entry time exceeds 95h 59m, see service " + HC);
13306 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13332 (AVEntry.
Command ==
"Fns-sh") || (AVEntry.
Command ==
"F-nshs"));
13340 if(HeadCode.Length() > 4)
13342 HeadCode = HeadCode.SubString(HeadCode.Length() - 3, 4);
13353 int ForwardCount = 0;
13354 int ReverseCount = 0;
13356 if(MainHeadCode == SecondHeadCode)
13358 SecondPassMessage(GiveMessages,
"Error in timetable - Service " + MainHeadCode +
" has an event that references itself");
13367 if(TDEntry.
HeadCode == MainHeadCode)
13369 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13384 if(ForwardCount == 0)
13387 throw Exception(
"Error, ForwardCount == 0 in CheckForDuplicateCrossReferences after called with found values");
13389 if(ForwardCount > 2)
13392 SecondPassMessage(GiveMessages,
"Error in timetable - found more than two references to " + SecondHeadCode +
" from a train whose headcode is " +
13393 MainHeadCode +
". Check the service cross references from each service, and check whether one or other service is listed twice or more.");
13402 if(TDEntry.
HeadCode == SecondHeadCode)
13404 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13419 if(ReverseCount == 0)
13421 SecondPassMessage(GiveMessages,
"Error in timetable - cross reference missing in either " + MainHeadCode +
" or " + SecondHeadCode);
13426 if(ReverseCount > 2)
13429 SecondPassMessage(GiveMessages,
"Error in timetable - found more than two references to " + MainHeadCode +
" from a train whose headcode is " +
13430 SecondHeadCode +
". Check the service cross references from each service, and check whether one or other service is listed twice or more.");
13435 if(ForwardCount != ReverseCount)
13437 SecondPassMessage(GiveMessages,
"Error in timetable - " + MainHeadCode +
" has a different number of references to " + SecondHeadCode +
13438 " than the other way round");
13469 int ForwardCount = 0;
13470 int ReverseCount = 0;
13471 unsigned int ForwardTDVectorNumber, ReverseTDVectorNumber;
13480 if(TDEntry.
HeadCode == MainHeadCode)
13482 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13485 if(!Shuttle && (AVEntry.
Command !=
"Sns-sh") && (AVEntry.
Command !=
"Snt-sh") && (AVEntry.
Command !=
"Fns-sh") && (AVEntry.
Command !=
"Frh-sh"))
13490 ForwardEntryPtr = &AVEntry;
13492 ForwardTDVectorNumber = x;
13495 else if(Shuttle && ((AVEntry.
Command ==
"Sns-sh") || (AVEntry.
Command ==
"Snt-sh") || (AVEntry.
Command ==
"Fns-sh") ||
13496 (AVEntry.
Command ==
"Frh-sh")))
13501 ForwardEntryPtr = &AVEntry;
13503 ForwardTDVectorNumber = x;
13509 if(ForwardCount == 0)
13512 throw Exception(
"Error, ForwardCount == 0 in CheckCrossReferencesAndSetData after called with found values");
13514 if(ForwardCount > 1)
13516 SecondPassMessage(GiveMessages,
"Error in timetable - found more than one reference to " + OtherHeadCode +
" from a train whose headcode is " +
13526 if(TDEntry.
HeadCode == OtherHeadCode)
13528 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13531 if(!Shuttle && (AVEntry.
Command !=
"Sns-sh") && (AVEntry.
Command !=
"Snt-sh") && (AVEntry.
Command !=
"Fns-sh") && (AVEntry.
Command !=
"Frh-sh"))
13537 ReverseEntryPtr = &AVEntry;
13538 ReverseTDVectorNumber = x;
13541 else if(Shuttle && ((AVEntry.
Command ==
"Sns-sh") || (AVEntry.
Command ==
"Snt-sh") || (AVEntry.
Command ==
"Fns-sh") || (AVEntry.
Command ==
"Frh-sh")))
13547 ReverseEntryPtr = &AVEntry;
13548 ReverseTDVectorNumber = x;
13555 if(ReverseCount == 0)
13557 SecondPassMessage(GiveMessages,
"Error in timetable - cross reference missing in either " + MainHeadCode +
" or " + OtherHeadCode);
13562 if(ReverseCount > 1)
13564 SecondPassMessage(GiveMessages,
"Error in timetable - found more than one reference to " + MainHeadCode +
" from a train whose headcode is " +
13571 bool ForwardShuttleStart = ((ForwardEntryPtr->Command ==
"Sns-sh") || (ForwardEntryPtr->Command ==
"Snt-sh"));
13572 bool ForwardShuttleFinish = ((ForwardEntryPtr->Command ==
"Fns-sh") || (ForwardEntryPtr->Command ==
"Frh-sh"));
13573 bool ReverseShuttleStart = ((ReverseEntryPtr->
Command ==
"Sns-sh") || (ReverseEntryPtr->
Command ==
"Snt-sh"));
13574 bool ReverseShuttleFinish = ((ReverseEntryPtr->
Command ==
"Fns-sh") || (ReverseEntryPtr->
Command ==
"Frh-sh"));
13578 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle train " + MainHeadCode +
" does not have a repeat");
13585 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle train " + OtherHeadCode +
" does not have a repeat");
13590 if(ForwardEntryPtr->LocationName ==
"")
13592 SecondPassMessage(GiveMessages,
"Error in timetable - location error in cross referenced trains " + MainHeadCode +
" and " + OtherHeadCode +
13593 ". One or other service does not have a location set");
13600 SecondPassMessage(GiveMessages,
"Error in timetable - location error in cross referenced trains " + MainHeadCode +
" and " + OtherHeadCode +
13601 ". One or other service does not have a location set");
13606 if(ForwardEntryPtr->LocationName != ReverseEntryPtr->
LocationName)
13608 SecondPassMessage(GiveMessages,
"Error in timetable - cross referenced train " + OtherHeadCode +
13609 " is at a different location to the referencing train " + MainHeadCode);
13617 if(ForwardEntryPtr->EventTime != ReverseEntryPtr->
EventTime)
13619 SecondPassMessage(GiveMessages,
"Error in timetable - cross referenced train " + OtherHeadCode +
13620 " has a different event time to the referencing train " + MainHeadCode);
13628 if(ForwardShuttleStart && ReverseShuttleFinish)
13633 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle service " + MainHeadCode +
13634 " first repeat restart time not consistent with finish service " + OtherHeadCode);
13640 if((ReverseEntryPtr->
Command ==
"Sfs") || (ReverseEntryPtr->
Command ==
"Sns"))
13643 if(ReverseTDVectorNumber == ForwardTDVectorNumber)
13645 SecondPassMessage(GiveMessages,
"Error in timetable - an 'Sfs' or 'Sns' event (" + OtherHeadCode +
13646 ") appears in the same sequence as the corresponding linked event " + MainHeadCode);
13652 if(ReverseEntryPtr->
Command ==
"Fjo")
13655 if(ReverseTDVectorNumber == ForwardTDVectorNumber)
13657 SecondPassMessage(GiveMessages,
"Error in timetable - an 'Fjo' event (" + OtherHeadCode +
13658 ") appears in the same sequence as the corresponding linked event " + MainHeadCode);
13664 if(ReverseEntryPtr->
Command ==
"Fns")
13667 if(ReverseTDVectorNumber == ForwardTDVectorNumber)
13669 SecondPassMessage(GiveMessages,
"Error in timetable - an 'Fns' event (" + OtherHeadCode +
13670 ") appears in the same sequence as the corresponding linked event " + MainHeadCode);
13676 if(ForwardEntryPtr->Command ==
"Sfs")
13678 if((ReverseEntryPtr->
Command !=
"fsp") && (ReverseEntryPtr->
Command !=
"rsp"))
13681 "Error in timetable - unable to find a corresponding split train event for the train that starts from a split whose headcode is " +
13688 if((ForwardEntryPtr->Command ==
"fsp") || (ForwardEntryPtr->Command ==
"rsp"))
13690 if(ReverseEntryPtr->
Command !=
"Sfs")
13692 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'Sfs' event for the train split whose headcode is " +
13702 SecondPassMessage(GiveMessages,
"Error in timetable - can't find timetabled location '" + ForwardEntryPtr->LocationName +
"' in railway - perhaps there are concourses without platforms?");
13709 SecondPassMessage(GiveMessages,
"Error in timetable - can't find any named location elements at '" + ForwardEntryPtr->LocationName +
"' - perhaps there are concourses without platforms?");
13716 SecondPassMessage(GiveMessages,
"Error in timetable - location too short to split a train at " + ForwardEntryPtr->LocationName);
13721 ForwardEntryPtr->LinkedTrainEntryPtr = OtherTrainDataPtr;
13732 if(ForwardEntryPtr->Command ==
"Sns")
13734 if(ReverseEntryPtr->
Command !=
"Fns")
13736 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'Fns' event for the 'Sns' train whose headcode is " +
13737 MainHeadCode +
" and is formed from a service with headcode " + OtherHeadCode);
13743 if(ForwardEntryPtr->Command ==
"Fns")
13745 if(ReverseEntryPtr->
Command !=
"Sns")
13747 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'Sns' event for the train whose headcode is " + MainHeadCode +
13748 " and forms a new service with headcode " + OtherHeadCode);
13755 ForwardEntryPtr->LinkedTrainEntryPtr = OtherTrainDataPtr;
13766 if(ForwardEntryPtr->Command ==
"jbo")
13768 if(ReverseEntryPtr->
Command !=
"Fjo")
13770 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'Fjo' event for the train whose headcode is " + MainHeadCode +
13771 " and is joined by a train with headcode " + OtherHeadCode);
13777 if(ForwardEntryPtr->Command ==
"Fjo")
13779 if(ReverseEntryPtr->
Command !=
"jbo")
13781 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'jbo' event for the train whose headcode is " + MainHeadCode +
13782 " and joins a train with headcode " + OtherHeadCode);
13789 ForwardEntryPtr->LinkedTrainEntryPtr = OtherTrainDataPtr;
13799 if(ForwardShuttleStart)
13802 if(!ReverseShuttleFinish)
13805 SecondPassMessage(GiveMessages,
"Error in timetable - incorrect shuttle link to train whose headcode is " + MainHeadCode +
13806 " from train whose headcode is " + OtherHeadCode +
", has to be Fns-sh, Frh-sh");
13812 if(ReverseShuttleStart)
13815 if(!ForwardShuttleFinish)
13818 SecondPassMessage(GiveMessages,
"Error in timetable - incorrect shuttle link to train whose headcode is " + OtherHeadCode +
13819 " from train whose headcode is " + MainHeadCode +
", has to be Fns-sh, Frh-sh");
13826 ForwardEntryPtr->LinkedTrainEntryPtr = OtherTrainDataPtr;
13838 bool MainRepeat =
false, OtherRepeat =
false;
13848 OtherRepeat =
true;
13851 if((MainRepeat && !OtherRepeat) || (!MainRepeat && OtherRepeat))
13853 SecondPassMessage(GiveMessages,
"Error in timetable - only one repeat is provided for the train whose headcode is " + MainHeadCode +
13854 " and the associated train with headcode " + OtherHeadCode);
13859 if(MainRepeat && OtherRepeat)
13865 SecondPassMessage(GiveMessages,
"Error in timetable - repeat items don't correspond for the train whose headcode is " + MainHeadCode +
13866 " and the associated train with headcode " + OtherHeadCode);
13888 while(Input[1] ==
' ')
13890 if(Input.Length() > 1)
13892 Input = Input.SubString(2, Input.Length() - 1);
13906 while(Input[Input.Length()] ==
' ')
13908 if(Input.Length() > 1)
13910 Input = Input.SubString(1, Input.Length() - 1);
13920 AnsiString Output =
"";
13921 bool DelimiterFound =
false;
13923 for(
int x = 1; x < Input.Length() + 1; x++)
13927 if(Input[x] ==
' ')
13932 if((Input[x] !=
',') && (Input[x] !=
';'))
13934 DelimiterFound =
false;
13935 Output = Output + Input[x];
13939 DelimiterFound =
true;
13940 Output = Output + Input[x];
13952 DelimiterFound =
false;
13953 for(
int x = Input.Length(); x > 0; x--)
13957 if(Input[x] ==
' ')
13962 if((Input[x] !=
',') && (Input[x] !=
';'))
13964 DelimiterFound =
false;
13965 Output = AnsiString(Input[x]) + Output;
13969 DelimiterFound =
true;
13970 Output = AnsiString(Input[x]) + Output;
13995 if((AVEntry0.
Command !=
"Snt") && (AVEntry0.
Command !=
"Snt-sh"))
13997 throw Exception(
"Error, first entry not 'Snt' or 'Snt-sh' in IsSNTEntryLocated");
14009 LocationName = LocRear;
14013 LocationName = LocFront;
14015 if(LocationName ==
"")
14036 for(
unsigned int y = 0; y < TDEntry.
ActionVector.size(); y++)
14077 int RearPosition = 0, FrontPosition = 0, RearExitPos = 0;
14080 if(RearPosition < 0)
14087 if(FrontPosition < 0)
14098 for(
int x = 0; x < 4; x++)
14100 if(RearTrackElement.
Conn[x] == FrontPosition)
14115 TimetableMessage(GiveMessages,
"Front of train attempting to start on a continuation at: " + FrontElementStr);
14122 TimetableMessage(GiveMessages,
"Train attempting to start on a level crossing at: " + FrontElementStr);
14128 TimetableMessage(GiveMessages,
"Train attempting to start on a level crossing at: " + RearElementStr);
14133 if((RearType ==
Points) && (RearExitPos == 3))
14135 TimetableMessage(GiveMessages,
"Front of train attempting to start on element connected to diverging points at: " + RearElementStr);
14141 TimetableMessage(GiveMessages,
"Rear of train attempting to start on element connected to diverging points at: " + FrontElementStr);
14156 AnsiString(RearExitPos));
14167 int FrontPosition = RearTrackElement.
Conn[RearExitPos];
14169 int FrontEntryPos = RearTrackElement.
ConnLinkPos[RearExitPos];
14172 AnsiString RearName, FrontName;
14188 FrontName = FrontTrackElement.
ElementID;
14191 int LockedVectorNumber;
14361 "," + AnsiString(IncDigits));
14364 throw Exception(
"Error, last 2 characters not both digits and IncDigits > 0 in GetRepeatHeadCode");
14369 return(BaseHeadCode);
14371 int BaseDigits = BaseHeadCode.SubString(3, 2).ToInt();
14372 int NextRepeatDigits = BaseDigits + (IncDigits * RepeatNumber);
14374 while(NextRepeatDigits >= 100)
14376 NextRepeatDigits -= 100;
14378 AnsiString NextRepeatDigitsStr = AnsiString(NextRepeatDigits);
14380 if(NextRepeatDigitsStr.Length() < 2)
14382 NextRepeatDigitsStr = AnsiString(
'0') + NextRepeatDigitsStr;
14384 AnsiString NextRepeatHeadCode = BaseHeadCode.SubString(1, 2) + NextRepeatDigitsStr;
14387 return(NextRepeatHeadCode);
14395 AnsiString(RepeatNumber) +
"," + AnsiString(IncMinutes));
14396 TDateTime NextRepeatTime = BasicTime + TDateTime(((
double)(RepeatNumber * IncMinutes)) / 1440.0);
14398 return(NextRepeatTime);
14407 AnsiString(
double(ReverseEventTime)) +
"," + AnsiString(RepeatMinutes));
14408 int ForwardSecs = int(
double(ForwardEventTime) * 86400);
14409 int ReverseSecs = int(
double(ReverseEventTime) * 86400);
14410 int RepeatSecs = RepeatMinutes * 60;
14412 if((ForwardSecs > (ReverseSecs - RepeatSecs + 10)) || (ForwardSecs < (ReverseSecs - RepeatSecs - 10)))
14447 NonRepeatingHeadCode);
14448 int ForwardCount = 0;
14449 int ReverseCount = 0;
14450 unsigned int ForwardTDVectorNumber, ReverseTDVectorNumber;
14460 if(TDEntry.
HeadCode == MainHeadCode)
14462 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
14468 ForwardEntryPtr = &AVEntry;
14470 ForwardTDVectorNumber = x;
14475 if(ForwardCount == 0)
14478 throw Exception(
"Error, ForwardCount == 0 in CheckNonRepeatingShuttleLinksAndSetData after called with found values");
14480 if(ForwardCount > 1)
14482 SecondPassMessage(GiveMessages,
"Error in timetable - found more than one reference to " + NonRepeatingHeadCode +
" from a train whose headcode is " +
14492 if(TDEntry.
HeadCode == NonRepeatingHeadCode)
14494 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
14501 ReverseEntryPtr = &AVEntry;
14502 ReverseTDVectorNumber = x;
14508 if(ReverseCount == 0)
14510 SecondPassMessage(GiveMessages,
"Error in timetable - cross reference missing in either " + MainHeadCode +
" or " + NonRepeatingHeadCode);
14515 if(ReverseCount > 1)
14517 SecondPassMessage(GiveMessages,
"Error in timetable - found more than one reference to " + MainHeadCode +
" from a train whose headcode is " +
14518 NonRepeatingHeadCode);
14523 if(((ForwardEntryPtr->Command ==
"F-nshs") || (ForwardEntryPtr->Command ==
"Sns-fsh")) && (MainTrainDataPtr->
ActionVector.back().FormatType ==
Repeat))
14525 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle connecting train " + MainHeadCode +
" shouldn't have a repeat");
14530 if((ForwardEntryPtr->Command !=
"F-nshs") && (ForwardEntryPtr->Command !=
"Sns-fsh") && (MainTrainDataPtr->
ActionVector.back().FormatType !=
Repeat))
14532 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle train " + MainHeadCode +
" does not have a repeat item");
14537 if(ForwardEntryPtr->LocationName ==
"")
14539 SecondPassMessage(GiveMessages,
"Error in timetable - location error in cross referenced trains " + MainHeadCode +
" and " + NonRepeatingHeadCode +
14540 ". One or other service does not have a location set");
14547 SecondPassMessage(GiveMessages,
"Error in timetable - location error in cross referenced trains " + MainHeadCode +
" and " + NonRepeatingHeadCode +
14548 ". One or other service does not have a location set");
14553 if(ForwardEntryPtr->LocationName != ReverseEntryPtr->
LocationName)
14555 SecondPassMessage(GiveMessages,
"Error in timetable - cross referenced train " + NonRepeatingHeadCode +
14556 " is at a different location to the referencing train " + MainHeadCode);
14561 if(ForwardEntryPtr->Command ==
"F-nshs")
14564 if(ForwardEntryPtr->EventTime != ReverseEntryPtr->
EventTime)
14566 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle in-link service " + MainHeadCode +
14567 " finish time not consistent with start time of shuttle service " + NonRepeatingHeadCode);
14573 if(ForwardEntryPtr->Command ==
"Fns-sh")
14577 MainTrainDataPtr->
ActionVector.back().RearStartOrRepeatMins, MainTrainDataPtr->
ActionVector.back().NumberOfRepeats))
14579 SecondPassMessage(GiveMessages,
"Error in timetable - service " + NonRepeatingHeadCode +
", which links out from shuttle service " + MainHeadCode +
14580 ", has the wrong start time. It should correspond to the finish time of the last shuttle.");
14586 if((ForwardEntryPtr->Command ==
"F-nshs") || (ForwardEntryPtr->Command ==
"Sns-fsh"))
14589 if(ReverseTDVectorNumber == ForwardTDVectorNumber)
14591 SecondPassMessage(GiveMessages,
"Error in timetable - the non repeating link service " + NonRepeatingHeadCode +
14592 " appears in the same sequence as the corresponding shuttle service " + MainHeadCode);
14610 if(ForwardEntryPtr->Command ==
"Sns-sh")
14612 if(ReverseEntryPtr->
Command !=
"F-nshs")
14614 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'F-nshs' event for the 'Sns-sh' train whose headcode is " +
14615 MainHeadCode +
" and is a new shuttle service formed from the service with headcode " + NonRepeatingHeadCode);
14621 if(ForwardEntryPtr->Command ==
"F-nshs")
14623 if(ReverseEntryPtr->
Command !=
"Sns-sh")
14625 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'Sns-sh' event for the 'F-nshs' train whose headcode is " +
14626 MainHeadCode +
" and forms a new shuttle service with headcode " + NonRepeatingHeadCode);
14633 ForwardEntryPtr->LinkedTrainEntryPtr = OtherTrainDataPtr;
14644 if(ForwardEntryPtr->Command ==
"Sns-fsh")
14646 if(ReverseEntryPtr->
Command !=
"Fns-sh")
14649 "Error in timetable - unable to find a corresponding 'Fns-sh' event for the 'Sns-fsh' non-shuttle service whose headcode is " + MainHeadCode +
14650 " formed from a shuttle service with headcode " + NonRepeatingHeadCode);
14656 if(ForwardEntryPtr->Command ==
"Fns-sh")
14658 if(ReverseEntryPtr->
Command !=
"Sns-fsh")
14661 "Error in timetable - unable to find a corresponding 'Sns-fsh' event for the 'Fns-sh' shuttle service whose headcode is " + MainHeadCode +
14662 " and forms a new non-shuttle service with headcode " + NonRepeatingHeadCode);
14669 ForwardEntryPtr->NonRepeatingShuttleLinkEntryPtr = OtherTrainDataPtr;
14693 +
"," + AnsiString(
double(ReverseEventTime)) +
"," + AnsiString(RepeatMinutes) +
"," + AnsiString(RepeatNumber));
14694 int ForwardSecs = int(
double(ForwardEventTime) * 86400);
14695 int ReverseSecs = int(
double(ReverseEventTime) * 86400);
14696 int RepeatSecs = RepeatMinutes * RepeatNumber * 60;
14698 if((ReverseSecs > (ForwardSecs + RepeatSecs + 10)) || (ReverseSecs < (ForwardSecs + RepeatSecs - 10)))
14722 throw Exception(
"Error - last entry in " + TDEntryPtr->
HeadCode +
" service is not a repeat - should have already found this error");
14725 AnsiString OriginalHeadCode = TDEntryPtr->
HeadCode;
14726 AnsiString LastActionCommand = (TDEntryPtr->
ActionVector.end() - 2)->Command;
14728 if((LastActionCommand !=
"Fns") && (LastActionCommand !=
"Fns-sh") && (LastActionCommand !=
"Frh-sh"))
14730 SecondPassMessage(GiveMessages,
"Error in timetable - last event in shuttle service " + TDEntryPtr->
HeadCode +
" is not 'Fns', 'Fns-sh' or 'Frh-sh'");
14735 while(LastActionCommand ==
"Fns")
14737 TDEntryPtr = (TDEntryPtr->
ActionVector.end() - 2)->LinkedTrainEntryPtr;
14738 LastActionCommand = (TDEntryPtr->
ActionVector.end() - 2)->Command;
14739 if((LastActionCommand !=
"Fns") && (LastActionCommand !=
"Fns-sh") && (LastActionCommand !=
"Frh-sh"))
14742 "Error in timetable - last event in a continuation shuttle service (i.e links back to a shuttle) whose headcode is " + TDEntryPtr->
HeadCode +
14743 " is not 'Fns', 'Fns-sh' or 'Frh-sh'");
14750 if((TDEntryPtr->
ActionVector.end() - 2)->LinkedTrainEntryPtr != ShuttleStartAddress)
14753 " is a shuttle finish, but it doesn't link back to the start of the original shuttle starting service " + OriginalHeadCode +
14754 ". The linking of two or more shuttles is not permitted.");
14774 ShowMessage(Message);
14792 ShowMessage(Message);
14831 AnsiString(ActionEventType) +
"," + LocationID);
14832 AnsiString BaseLog =
"", Prefix =
"", ErrorLog =
"", WarningStr =
"";
14837 Prefix =
" ERROR: ";
14840 Prefix =
" HELD: ";
14841 ErrorLog =
" can't enter railway, train obstructing entry position ";
14842 WarningStr =
" can't enter railway, train obstructing entry position ";
14847 Prefix =
" HELD: ";
14848 ErrorLog =
" can't enter railway, route set against it at entry position ";
14849 WarningStr =
" can't enter railway, route set against it at entry position ";
14854 Prefix =
" HELD: ";
14855 ErrorLog =
" can't be created, train obstructing ";
14856 WarningStr =
" can't be created, train obstructing ";
14861 Prefix =
" HELD: ";
14862 ErrorLog =
" can't be created on a locked route at ";
14863 WarningStr =
" can't be created on a locked route at ";
14868 Prefix =
" HELD: ";
14869 ErrorLog =
" can't enter on a locked route at ";
14870 WarningStr =
" can't enter on a locked route at ";
14875 Prefix =
" HELD: ";
14876 ErrorLog =
" can't be created, diverging points at ";
14877 WarningStr =
" can't be created, diverging points at ";
14882 ErrorLog =
" left railway unexpectedly at ";
14887 ErrorLog =
" left railway at an incorrect exit at ";
14892 ErrorLog =
" failed to split - location too short at ";
14893 WarningStr =
" failed to split, location too short at ";
14898 Prefix =
" HELD: ";
14899 ErrorLog =
" unable to split - other train obstructing at ";
14900 WarningStr =
" unable to split - other train obstructing at ";
14905 ErrorLog =
" stopped at buffers unexpectedly at position ";
14909 ErrorLog =
" failed to stop at ";
14914 ErrorLog =
" failed to split at ";
14919 ErrorLog =
" failed to be joined by other train at ";
14924 ErrorLog =
" failed to join other train at ";
14929 ErrorLog =
" failed to terminate at ";
14934 ErrorLog =
" failed to form new service at ";
14939 ErrorLog =
" failed to exit railway ";
14944 ErrorLog =
" failed to change direction at ";
14949 ErrorLog =
" failed to pass ";
14954 ErrorLog =
" facing buffers and unable to start at ";
14958 ErrorLog =
" DERAILED at position ";
14959 Prefix =
" DERAILMENT: ";
14964 ErrorLog =
" CRASHED INTO BUFFERS at ";
14965 Prefix =
" CRASH: ";
14970 ErrorLog =
" CRASHED INTO ROAD TRAFFIC AT A LEVEL CROSSING at ";
14971 Prefix =
" CRASH: ";
14976 ErrorLog =
" CRASHED INTO " + OtherHeadCode +
" at position ";
14977 Prefix =
" CRASH: ";
14981 else if(ActionEventType ==
FailSPAD)
14983 ErrorLog =
" PASSED SIGNAL AT DANGER at position ";
14984 Prefix =
" SPAD: ";
14989 ErrorLog =
"Signals reset ahead of train, route cancelled at position ";
14990 Prefix =
" SPAD RISK: ";
14995 ErrorLog =
" forced a route cancellation by occupying it incorrectly at ";
14999 Prefix =
" WARNING: ";
15000 ErrorLog =
" waiting to join " + OtherHeadCode +
" at ";
15001 WarningStr =
" waiting to join " + OtherHeadCode +
" at ";
15006 Prefix =
" WARNING: ";
15007 ErrorLog =
" waiting to be joined by " + OtherHeadCode +
" at ";
15008 WarningStr =
" waiting to be joined by " + OtherHeadCode +
" at ";
15046 std::ofstream OutFile(
"TrainData.csv");
15050 ShowMessage(
"Output file TrainData.csv failed to open");
15057 OutFile <<
"HeadCode" <<
',' <<
"Description" <<
',' <<
"StartSpeed" <<
',' <<
"MaxRunningSpeed" <<
',' <<
"NumberOfTrains" <<
'\n' <<
'\n';
15062 OutFile <<
',' <<
"FormatType" <<
',' <<
"EventTime" <<
',' <<
"ArrivalTime" <<
',' <<
"DepartureTime" <<
',' <<
"LocationName" <<
',' <<
"Command" <<
15063 ',' <<
"OtherHeadCode" <<
',' <<
"LinkedTrainEntryPtr" <<
',' <<
"RearStartOrRepeatMins" <<
',' <<
"FrontStartOrRepeatDigits" <<
',' <<
15064 "RepeatNumber" <<
'\n' <<
'\n';
15065 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
15068 AnsiString TimetableEntryTypeStr;
15074 TimetableEntryTypeStr =
"NoFormat";
15080 TimetableEntryTypeStr =
"TimeLoc";
15086 TimetableEntryTypeStr =
"TimeTimeLoc";
15092 TimetableEntryTypeStr =
"TimeCmd";
15098 TimetableEntryTypeStr =
"StartNew";
15104 TimetableEntryTypeStr =
"TimeCmdHeadCode";
15110 TimetableEntryTypeStr =
"FinRemHere";
15116 TimetableEntryTypeStr =
"FNSShuttle";
15122 TimetableEntryTypeStr =
"SNTShuttle";
15128 TimetableEntryTypeStr =
"SNSShuttle";
15134 TimetableEntryTypeStr =
"SNSNonRepeatFromShuttle";
15140 TimetableEntryTypeStr =
"FSHNewService";
15146 TimetableEntryTypeStr =
"Repeat";
15152 TimetableEntryTypeStr =
"Default";
15163 OutFile <<
',' <<
',' <<
"Mass" <<
',' <<
"MaxBrakeRate" <<
',' <<
"PowerAtRail" <<
',' <<
"TrainID" <<
',' <<
"RunningEntry" <<
'\n' <<
'\n';
15164 for(
unsigned int y = 0; y <
TrainDataVector.at(x).TrainOperatingDataVector.size(); y++)
15167 AnsiString RunningEntryStr;
15173 RunningEntryStr =
"NotStarted";
15179 RunningEntryStr =
"Running";
15185 RunningEntryStr =
"Exited";
15189 OutFile <<
',' <<
',' << TOD.
TrainID <<
',' << RunningEntryStr.c_str() <<
',' <<
'\n';
15206 ShowMessage(Message);
15207 BaseTime = TDateTime::CurrentDateTime();
15221 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
15234 TTrain *NewTrain =
new TTrain(1, 0, 0,
"", 0, 1, 0, 0, 0, (
TTrainMode)0, 0, 0, 0, 0, 0);
15236 for(
int x = 0; x < NumberOfTrains; x++)
15238 *NewTrain =
TTrain(2, 0, 0,
"", 0, 1, 0, 0, 0, (
TTrainMode)0, 0, 0, 0, 0, 0);
15258 int NumberOfTrains;
15265 for(
int x = 0; x < NumberOfTrains; x++)
15302 for(
int x = 0; x < LockedRouteVectorSize; x++)
15309 LockedRouteObject.
LockStartTime = TDateTime(LockStartTimeDouble);
15320 int LockedRouteVectorSize;
15327 for(
int x = 0; x < LockedRouteVectorSize; x++)
15385 for(
int x = 0; x < ContinuationAutoSigVectorSize; x++)
15393 ContinuationAutoSigObject.
PassoutTime = TDateTime(PassoutTimeDouble);
15404 int ContinuationAutoSigVectorSize;
15411 for(
int x = 0; x < ContinuationAutoSigVectorSize; x++)
15481 if(AVFirstEntry.
Command ==
"Snt")
15505 CTEMMP.second = CTEEntry;
15512 throw Exception(
"Error, Last ActionVectorEntry not a repeat in BuildContinuationTrainExpectationMultiMap");
15520 CTEMMP.second = CTEEntry;
15541 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
15558 if((VecPos < 0) || (VecPos >= (
int)
TrainVector.size()))
15560 throw Exception(
"Out of Range Error, vector size: " + AnsiString(
TrainVector.size()) +
", VecPos: " + AnsiString(VecPos) +
" in TrainVectorAt");
15571 AnsiString RetStr =
"", PartStr =
"";
15686 AnsiString TTFileName = TDateTime::CurrentDateTime().FormatString(
"dd-mm-yyyy hh.nn.ss");
15690 TTFileName = CurDir +
"\\Formatted timetables\\Timetable " + TTFileName +
"; " + RailwayTitle +
"; " + TimetableTitle +
".csv";
15692 AnsiString ShortTTName =
"";
15694 for(
int x = TTFileName.Length(); x > 0; x--)
15696 if(TTFileName[x] ==
'\\')
15698 ShortTTName = TTFileName.SubString(x + 1, TTFileName.Length() - x - 4);
15703 ShowMessage(
"Creates two timetables named " + ShortTTName +
15704 " in the 'Formatted timetables' folder, one in service order in '.csv' format, and one in chronological order in '.txt' format");
15706 Screen->Cursor = TCursor(-11);
15708 AnsiString FormatNoDPStr =
"#######0";
15709 AnsiString TableTitle =
"", TimetableTimeStr =
"", MassStr =
"", PowerStr =
"", BrakeStr =
"", MaxSpeedStr =
"", FirstHeadCode =
"", Header =
"";
15712 TableTitle =
"Railway: " + RailwayTitle +
"; Timetable: " + TimetableTitle +
"; Start time: " + TimetableTimeStr;
15719 MassStr =
"", PowerStr =
"", BrakeStr =
"", MaxSpeedStr =
"";
15721 if(TrainDataEntry.
Mass > 0)
15723 MassStr =
"; Mass " + AnsiString::FormatFloat(FormatNoDPStr, ((
double)TrainDataEntry.
Mass) / 1000) +
"Te; ";
15727 PowerStr =
"Power " + AnsiString::FormatFloat(FormatNoDPStr, TrainDataEntry.
PowerAtRail / 1000 / 0.8) +
"kW; ";
15731 BrakeStr =
"Brake force " + AnsiString::FormatFloat(FormatNoDPStr, (TrainDataEntry.
MaxBrakeRate * TrainDataEntry.
Mass / 9810)) +
"Te; ";
15735 MaxSpeedStr =
"Maximum speed " + AnsiString::FormatFloat(FormatNoDPStr, TrainDataEntry.
MaxRunningSpeed) +
" km/h";
15737 FirstHeadCode = TrainDataEntry.
HeadCode;
15738 int IncDigits = 0, IncMinutes = 0;
15740 if(!ActionVector.empty())
15742 if(ActionVector.at(ActionVector.size() - 1).FormatType ==
Repeat)
15744 IncDigits = ActionVector.at(ActionVector.size() - 1).FrontStartOrRepeatDigits;
15745 IncMinutes = ActionVector.at(ActionVector.size() - 1).RearStartOrRepeatMins;
15753 if((TrainDataEntry.
Description !=
"") && (MassStr !=
""))
15755 OneTTLine.
Header = TrainDataEntry.
Description + MassStr + PowerStr + BrakeStr + MaxSpeedStr;
15763 for(
unsigned int z = 0; z < ActionVector.size(); z++)
15768 AnsiString PartStr =
"", TimeStr =
"";
15785 PartStr =
"Enters at " + ActionVectorEntry.
LocationName;
15789 PartStr =
"Created at " + ActionVectorEntry.
LocationName;
15799 PartStr =
"Enters at " + LocName;
15812 PartStr =
"Created at " + LocName;
15826 PartStr =
"Enters at " + ActionVectorEntry.
LocationName;
15831 PartStr =
"Repeat shuttle service at " + ActionVectorEntry.
LocationName +
" from ";
15837 else if(ActionVectorEntry.
Command ==
"Sfs")
15839 PartStr =
"New service at " + ActionVectorEntry.
LocationName +
" split from";
15843 else if(ActionVectorEntry.
Command ==
"Sns")
15845 PartStr =
"New service at " + ActionVectorEntry.
LocationName +
" from";
15853 PartStr =
"New service at " + ActionVectorEntry.
LocationName +
" from";
15859 PartStr =
"Repeat shuttle service at " + ActionVectorEntry.
LocationName +
" from ";
15867 PartStr =
"New service at " + ActionVectorEntry.
LocationName +
" from";
15870 AnsiString FirstHeadCode = TDE->
HeadCode;
15874 TimeStr =
GetRepeatHeadCode(36, FirstHeadCode, LastRepeatNumber, IncrementalDigits) +
" at " +
15886 PartStr =
"Arrives at " + ActionVectorEntry.
LocationName;
15888 OneTTEntry.
Action = PartStr;
15889 OneTTEntry.
Time = TimeStr;
15891 PartStr =
"Departs from " + ActionVectorEntry.
LocationName;
15896 PartStr =
"Arrives & departs " + ActionVectorEntry.
LocationName;
15902 PartStr =
"Arrives at " + ActionVectorEntry.
LocationName;
15907 PartStr =
"Departs from " + ActionVectorEntry.
LocationName;
15915 else if(ActionVectorEntry.
Command ==
"jbo")
15917 PartStr =
"Joined at " + ActionVectorEntry.
LocationName +
" by";
15921 else if(ActionVectorEntry.
Command ==
"fsp")
15923 PartStr =
"Splits from front at " + ActionVectorEntry.
LocationName +
" to form";
15927 else if(ActionVectorEntry.
Command ==
"rsp")
15929 PartStr =
"Splits from rear at " + ActionVectorEntry.
LocationName +
" to form";
15933 else if(ActionVectorEntry.
Command ==
"cdt")
15935 PartStr =
"Changes direction at " + ActionVectorEntry.
LocationName;
15941 if(ActionVectorEntry.
Command ==
"Fns")
15943 PartStr =
"At " + ActionVectorEntry.
LocationName +
" forms new service";
15947 else if(ActionVectorEntry.
Command ==
"F-nshs")
15949 PartStr =
"At " + ActionVectorEntry.
LocationName +
" forms new service";
15955 PartStr =
"At " + ActionVectorEntry.
LocationName +
" forms new service ";
15962 PartStr =
"At " + ActionVectorEntry.
LocationName +
" forms new service";
15968 PartStr =
"At " + ActionVectorEntry.
LocationName +
" forms new service";
15975 PartStr =
"Terminates shuttle service at " + ActionVectorEntry.
LocationName;
15980 else if(ActionVectorEntry.
Command ==
"Frh")
15982 PartStr =
"Terminates at " + ActionVectorEntry.
LocationName;
15987 if(ActionVector.at(z - 1).EventTime != TDateTime(-1))
15991 else if(ActionVector.at(z - 1).ArrivalTime != TDateTime(-1))
16001 else if(ActionVectorEntry.
Command ==
"Fer")
16003 AnsiString AllowedExits;
16007 else if(ActionVectorEntry.
Command ==
"Fjo")
16009 PartStr =
"At " + ActionVectorEntry.
LocationName +
" joins";
16018 OneTTEntry.
Action = PartStr;
16019 OneTTEntry.
Time = TimeStr;
16026 AllTTTrains->push_back(OneTTLine);
16030 std::ofstream TTFile(TTFileName.c_str());
16034 StopTTClockMessage(64,
"Formatted timetable file failed to open - can't be created");
16035 delete AllTTTrains;
16070 TTFile << TableTitle.c_str() <<
'\n' <<
'\n';
16071 for(
unsigned int x = 0; x < AllTTTrains->size(); x++)
16073 TTFile << AllTTTrains->at(x).Header.c_str();
16076 for(
int y = 0; y < AllTTTrains->at(x).NumberOfTrains; y++)
16078 if(y < (AllTTTrains->at(x).NumberOfTrains - 1))
16080 TTFile << AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).HeadCode.c_str() <<
',';
16084 TTFile << AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).HeadCode.c_str();
16087 TTFile <<
'\n' <<
'\n';
16089 for(
unsigned int z = 0; z < AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(0).OneFormattedTrainVector.size(); z++)
16091 TTFile << AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(0).OneFormattedTrainVector.at(z).Action.c_str() <<
',';
16092 for(
int y = 0; y < AllTTTrains->at(x).NumberOfTrains; y++)
16094 if(y < (AllTTTrains->at(x).NumberOfTrains - 1))
16096 TTFile << AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).OneFormattedTrainVector.at(z).Time.c_str() <<
',';
16100 TTFile << AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).OneFormattedTrainVector.at(z).Time.c_str();
16105 TTFile <<
'\n' <<
'\n';
16110 AnsiString TTFileName2 = TDateTime::CurrentDateTime().FormatString(
"dd-mm-yyyy hh.nn.ss");
16112 TTFileName2 = CurDir +
"\\Formatted timetables\\Timetable " + TTFileName2 +
"; " + RailwayTitle +
"; " + TimetableTitle +
".txt";
16114 std::ofstream TTFile2(TTFileName2.c_str());
16118 StopTTClockMessage(67,
"Chronological timetable file failed to open - can't be created");
16119 delete AllTTTrains;
16123 typedef std::multimap<AnsiString, AnsiString>TAnsiMultiMap;
16124 std::multimap<AnsiString, AnsiString>::iterator AMMIT;
16125 std::pair<AnsiString, AnsiString>AnsiMultiMapEntry;
16127 TAnsiMultiMap *TAMM =
new TAnsiMultiMap;
16132 TTFile2 << TableTitle.c_str() <<
'\n' <<
'\n';
16133 for(
unsigned int x = 0; x < AllTTTrains->size(); x++)
16135 for(
int y = 0; y < AllTTTrains->at(x).NumberOfTrains; y++)
16137 for(
unsigned int z = 0; z < AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).OneFormattedTrainVector.size(); z++)
16139 bool GiveMessagesFalse =
false;
16140 AnsiString TimeString = AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).OneFormattedTrainVector.at(z).Time;
16141 AnsiString HeadCodeString = AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).HeadCode;
16142 AnsiString ActionString = AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).OneFormattedTrainVector.at(z).Action;
16147 AnsiString OtherHeadCode = TimeString.SubString(1, 4);
16148 TimeString = TimeString.SubString(9, 5);
16149 ActionString +=
" " + OtherHeadCode;
16151 if(TimeString.SubString(1, 7) ==
"End at ")
16154 TimeString = TimeString.SubString(8, 5);
16156 AnsiString OneLine = TimeString +
' ' + HeadCodeString +
' ' + ActionString +
'\n';
16157 AnsiMultiMapEntry.first = TimeString;
16158 AnsiMultiMapEntry.second = OneLine;
16159 TAMM->insert(AnsiMultiMapEntry);
16164 for(AMMIT = TAMM->begin(); AMMIT != TAMM->end(); AMMIT++)
16166 TTFile2 << (AMMIT->second).c_str();
16168 delete AllTTTrains;
16177 bool AtLocChecked,
bool DirChecked,
int ArrRange,
int DepRange)
16181 bool AnalysisError =
false;
16182 AnsiString SequenceLog =
"SequenceLog\n";
16224 TTrainDataVector::iterator TDVIt, TDVCopyIt;
16226 int IteratorNumber = 0;
16227 AnsiString AnsiSuffix =
"";
16232 for(TDVCopyIt = TrainDataVectorCopy.begin() + IteratorNumber; TDVCopyIt != TrainDataVectorCopy.end(); TDVCopyIt++)
16234 if(TDVCopyIt->ServiceReference == TDVIt->ServiceReference)
16237 AnsiSuffix = AnsiString(Suffix);
16238 TDVCopyIt->ServiceReference = TDVIt->ServiceReference +
"/" + AnsiSuffix;
16242 SequenceLog +=
"1\n";
16245 std::pair<AnsiString, TServiceCallingLocsList> AllServiceCallingLocsEntry;
16246 for(
unsigned int x = 0; x < TrainDataVectorCopy.size(); x++)
16251 ServiceCallingLocsList.clear();
16252 if(ActionVector.empty())
16256 if(ActionVector.at(0).SignallerControl)
16260 for(
unsigned int z = 0; z < ActionVector.size(); z++)
16278 int HLoc = TE.
HLoc;
16279 int VLoc = TE.
VLoc;
16280 AnsiString HString;
16281 AnsiString VString;
16284 HString = AnsiString(
'N') + AnsiString(HLoc).SubString(2, AnsiString(HLoc).Length() - 1);
16288 HString = AnsiString(HLoc);
16292 VString = AnsiString(
'N') + AnsiString(VLoc).SubString(2, AnsiString(VLoc).Length() - 1);
16296 VString = AnsiString(VLoc);
16298 ServiceCallingLocsList.push_back(HString +
'-' + VString);
16321 else if(AVE.
Command ==
"cdt")
16323 if(ActionVector.at(z-1).SequenceType ==
Start)
16327 else if(ActionVector.at(z+1).SequenceType ==
Finish)
16334 ServiceCallingLocsList.push_back(
"%%%" + TimeString);
16343 ServiceCallingLocsList.push_back(LName);
16347 int HLoc = TE.
HLoc;
16348 int VLoc = TE.
VLoc;
16349 AnsiString HString;
16350 AnsiString VString;
16353 HString = AnsiString(
'N') + AnsiString(HLoc).SubString(2, AnsiString(HLoc).Length() - 1);
16357 HString = AnsiString(HLoc);
16361 VString = AnsiString(
'N') + AnsiString(VLoc).SubString(2, AnsiString(VLoc).Length() - 1);
16365 VString = AnsiString(VLoc);
16367 ServiceCallingLocsList.push_back(HString +
'-' + VString);
16371 AllServiceCallingLocsEntry.second = ServiceCallingLocsList;
16375 SequenceLog +=
"2\n";
16405 ShowMessage(
"Unable to create a program-readable timetable - please check the timetable file validity");
16411 bool NumPlatsAtThisLocCalculated =
false, ArrivalsPrinted =
false, DeparturesPrinted =
false, AtLocsPrinted =
false;
16412 AnsiString PreviousService =
"", PreviousServiceAndRepeatNumTotalOutput =
"", BasicTime =
"", MinuteString =
"", LastAnsiTime =
"";
16413 int NumTrains = 0, NumPlats = 0, LastFrhCount = 0, FrhCount = 0, NumTrainsAtLoc = 0;
16415 SequenceLog +=
"3\n";
16417 for(
unsigned int x = 0; x < TrainDataVectorCopy.size(); x++)
16422 TDateTime LastTDTime;
16423 int IncMinutes = 0;
16425 if(ActionVector.empty())
16429 if(ActionVector.at(0).SignallerControl)
16433 if(AVLast->FormatType ==
Repeat)
16435 IncMinutes = ActionVector.at(ActionVector.size() - 1).RearStartOrRepeatMins;
16443 if(AVLast->ArrivalTime != TDateTime(-1))
16445 LastTDTime = AVLast->ArrivalTime;
16447 else if(AVLast->EventTime != TDateTime(-1))
16449 LastTDTime = AVLast->EventTime;
16468 SequenceLog +=
"4\n";
16500 for(
unsigned int x = 0; x < TrainDataVectorCopy.size(); x++)
16505 int IncMinutes = 0;
16507 if(ActionVector.empty())
16511 if(ActionVector.at(0).SignallerControl)
16515 if(ActionVector.at(ActionVector.size() - 1).FormatType ==
Repeat)
16517 IncMinutes = ActionVector.at(ActionVector.size() - 1).RearStartOrRepeatMins;
16519 for(
int y = 0; y < NumTrains; y++)
16533 for(
unsigned int z = 0; z < ActionVector.size(); z++)
16548 LocServiceTimesVector.push_back(TLSTEntry);
16551 AnsiString IncTime =
"", FoundStopTime =
"";
16552 for(
unsigned int a = z + 1; a < ActionVector.size(); a++)
16554 if(ActionVector.at(a).FormatType ==
TimeLoc)
16559 if(ActionVector.at(a).SequenceType ==
Finish)
16565 if(FoundStopTime ==
"")
16567 throw Exception(
"Failure to determine FoundStopTime for located Snt");
16569 int WhileCount = 0;
16578 if(IncTime >= FoundStopTime)
16582 LocServiceTimesVector.push_back(TLSTEntry);
16583 if(WhileCount > 2000)
16585 throw Exception(
"While loop failed to break in 2000 loops for located Snt");
16598 int HLoc = TE.
HLoc;
16599 int VLoc = TE.
VLoc;
16600 AnsiString HString;
16601 AnsiString VString;
16604 HString = AnsiString(
'N') + AnsiString(HLoc).SubString(2, AnsiString(HLoc).Length() - 1);
16608 HString = AnsiString(HLoc);
16612 VString = AnsiString(
'N') + AnsiString(VLoc).SubString(2, AnsiString(VLoc).Length() - 1);
16616 VString = AnsiString(VLoc);
16618 TLSTEntry.
Location = HString +
'-' + VString;
16622 LocServiceTimesVector.push_back(TLSTEntry);
16630 LocServiceTimesVector.push_back(TLSTEntry);
16632 AnsiString IncTime =
"", FoundStopTime =
"";
16633 for(
unsigned int a = z + 1; a < ActionVector.size(); a++)
16635 if(ActionVector.at(a).FormatType ==
TimeLoc)
16640 if(ActionVector.at(a).SequenceType ==
Finish)
16646 if(FoundStopTime ==
"")
16648 throw Exception(
"Failure to determine FoundStopTime for SequenceType == Start");
16650 int WhileCount = 0;
16659 if(IncTime >= FoundStopTime)
16663 LocServiceTimesVector.push_back(TLSTEntry);
16664 if(WhileCount > 2000)
16666 throw Exception(
"While loop failed to break in 2000 loops for SequenceType == Start");
16676 bool SkipAddingMinutes =
false;
16679 LocServiceTimesVector.push_back(TLSTEntry);
16681 AnsiString IncTime =
"", FoundStopTime =
"";
16682 for(
unsigned int a = z + 1; a < ActionVector.size(); a++)
16684 if(ActionVector.at(a).FormatType ==
TimeLoc)
16689 if(ActionVector.at(a).SequenceType ==
Finish)
16692 if((a <= (z + 2)) && (FoundStopTime == TLSTEntry.
ArrTime) && ((ActionVector.at(a).LinkedTrainEntryPtr > 0) || (ActionVector.at(a).NonRepeatingShuttleLinkEntryPtr > 0)))
16696 LocServiceTimesVector.pop_back();
16697 SkipAddingMinutes =
true;
16702 if(FoundStopTime ==
"")
16704 throw Exception(
"Failure to determine FoundStopTime for SequenceType == Start");
16706 if(!SkipAddingMinutes)
16708 int WhileCount = 0;
16717 if(IncTime >= FoundStopTime)
16721 LocServiceTimesVector.push_back(TLSTEntry);
16722 if(WhileCount > 2000)
16724 throw Exception(
"While loop failed to break in 2000 loops for SequenceType == Start");
16733 if((TLSTEntry.
Location == LocServiceTimesVector.back().Location) && (TLSTEntry.
ServiceAndRepeatNum == LocServiceTimesVector.back().ServiceAndRepeatNum))
16735 if(TLSTEntry.
DepTime == LocServiceTimesVector.back().ArrTime)
16737 TLSTEntry.
ArrTime = LocServiceTimesVector.back().ArrTime;
16738 LocServiceTimesVector.pop_back();
16739 LocServiceTimesVector.push_back(TLSTEntry);
16744 LocServiceTimesVector.push_back(TLSTEntry);
16750 LocServiceTimesVector.push_back(TLSTEntry);
16769 LocServiceTimesVector.push_back(TLSTEntry);
16773 AnsiString TempDepTime = TLSTEntry.
DepTime;
16775 LocServiceTimesVector.push_back(TLSTEntry);
16777 while(TLSTEntry.
AtLocTime < TempDepTime)
16782 TLSTEntry.
DepTime = TempDepTime;
16783 LocServiceTimesVector.push_back(TLSTEntry);
16787 LocServiceTimesVector.push_back(TLSTEntry);
16798 LocServiceTimesVector.push_back(TLSTEntry);
16801 LocServiceTimesVector.push_back(TLSTEntry);
16818 AnsiString HString;
16819 AnsiString VString;
16822 HString = AnsiString(
'N') + AnsiString(HLoc).SubString(2, AnsiString(HLoc).Length() - 1);
16826 HString = AnsiString(HLoc);
16830 VString = AnsiString(
'N') + AnsiString(VLoc).SubString(2, AnsiString(VLoc).Length() - 1);
16834 VString = AnsiString(VLoc);
16836 TLSTEntry.
Location = HString +
'-' + VString;
16838 LocServiceTimesVector.push_back(TLSTEntry);
16843 AnsiString FrhTime;
16844 if(ActionVector.at(z - 1).ArrivalTime != TDateTime(-1))
16848 else if(ActionVector.at(z - 1).EventTime != TDateTime(-1))
16856 LocServiceTimesVector.push_back(TLSTEntry);
16862 LocServiceTimesVector.push_back(TLSTEntry);
16867 else if(AVE.
Command ==
"Frh-sh")
16869 if(y == NumTrains - 1)
16875 LocServiceTimesVector.push_back(TLSTEntry);
16881 LocServiceTimesVector.push_back(TLSTEntry);
16894 SequenceLog +=
"5\n";
16922 TLocServiceTimesVector::iterator Ptr1, Ptr2;
16925 AnsiString TTFileName3 = TDateTime::CurrentDateTime().FormatString(
"dd-mm-yyyy hh.nn.ss");
16926 TTFileName3 = CurDir +
"\\Formatted timetables\\Conflict Analysis " + TTFileName3 +
"; " + RailwayTitle +
"; " + TimetableTitle +
".csv";
16928 std::ofstream TTFile3(TTFileName3.c_str());
16932 ShowMessage(
"Conflict Analysis file failed to open - can't be created");
16936 if(LocServiceTimesVector.empty())
16938 ShowMessage(
"No timetabled services found");
16940 DeleteFile(TTFileName3);
16944 TTFile3 <<
"Timetable analysis for timetable: '" + TimetableTitle +
"' in conjunction with railway: '" + RailwayTitle +
"'\n";
16945 TTFile3 <<
"See user manual or on-screen help section 5.12 for detailed information.\n\n\n";
16946 SequenceLog +=
"6\n";
16995 Ptr1 = LocServiceTimesVector.begin();
16997 while(Ptr2 != LocServiceTimesVector.end())
16999 while(Ptr2->Location == Ptr1->Location)
17002 if(Ptr2 == LocServiceTimesVector.end())
17009 if(Ptr2 != LocServiceTimesVector.end())
17017 TTFile3 <<
"Arrival & pass analysis: an asterisk means that the number of same approach code arrivals and passes is equal to or greater than the number of platforms.\n";
17018 TTFile3 <<
"If the total number of arrivals and passes at the same time exceeds the number of platforms the 'Trains present at location analysis' will show an asterisk.\n\n";
17019 MinuteString =
" minutes";
17020 AnsiString ServiceAndRepeatNumTotal =
"", ServiceAndRepeatNumTotalOutput =
"";
17023 MinuteString =
" minute";
17025 TTFile3 <<
"Location,Number of,Number of,Services arriving within " << AnsiString(ArrRange) << MinuteString <<
" with their arrival times and approach codes\n";
17026 TTFile3 <<
",Platforms,Trains\n\n";
17028 Ptr1 = LocServiceTimesVector.begin();
17030 while(Ptr2 != LocServiceTimesVector.end())
17032 PreviousService =
"";
17033 NumTrainsAtLoc = 0;
17034 ServiceAndRepeatNumTotal =
"";
17036 NumPlatsAtThisLocCalculated =
false;
17038 while((Ptr2->Location != Ptr1->Location) || ((Ptr1->Location ==
"") && (Ptr2->Location ==
"")))
17040 PreviousService =
"";
17041 NumTrainsAtLoc = 0;
17042 ServiceAndRepeatNumTotal =
"";
17044 NumPlatsAtThisLocCalculated =
false;
17048 if(Ptr2 == LocServiceTimesVector.end())
17053 if(Ptr2 == LocServiceTimesVector.end())
17057 while(Ptr2->Location == Ptr1->Location)
17059 PreviousService =
"";
17060 NumTrainsAtLoc = 0;
17061 ServiceAndRepeatNumTotal =
"";
17062 BasicTime = Ptr1->ArrTime;
17063 if((Ptr1->Location ==
"") && (Ptr2->Location ==
""))
17067 while(!
WithinTimeRange(0, BasicTime, Ptr2->ArrTime, ArrRange) || ((Ptr1->ArrTime ==
"") && (Ptr2->ArrTime ==
"")))
17069 BasicTime = Ptr2->ArrTime;
17072 if(Ptr2 == LocServiceTimesVector.end())
17076 if(Ptr2->Location != Ptr1->Location)
17081 if(Ptr2 == LocServiceTimesVector.end())
17085 if(Ptr2->Location != Ptr1->Location)
17091 if((Ptr1->ArrTime ==
"") && (Ptr2->ArrTime ==
""))
17095 if(!NumPlatsAtThisLocCalculated)
17098 NumPlatsAtThisLocCalculated =
true;
17100 if(Ptr1->ServiceAndRepeatNum != PreviousService)
17102 if(ServiceAndRepeatNumTotal ==
"")
17104 ServiceAndRepeatNumTotal = Ptr1->ServiceAndRepeatNum +
"," + Ptr1->ArrTime;
17105 NumTrainsAtLoc = 1;
17109 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr1->ServiceAndRepeatNum +
"," + Ptr1->ArrTime;
17112 PreviousService = Ptr2->ServiceAndRepeatNum;
17113 if(ServiceAndRepeatNumTotal ==
"")
17115 ServiceAndRepeatNumTotal = Ptr2->ServiceAndRepeatNum +
"," + Ptr2->ArrTime;
17116 NumTrainsAtLoc = 1;
17120 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr2->ServiceAndRepeatNum +
"," + Ptr2->ArrTime;
17124 if((Ptr2 == LocServiceTimesVector.end()) || (Ptr2->Location != Ptr1->Location) || (!
WithinTimeRange(2, BasicTime, Ptr2->ArrTime, ArrRange)))
17126 int MaxNumberOfSameDirections = 0;
17127 ServiceAndRepeatNumTotalOutput =
ConsolidateSARNTArrDep(1, ServiceAndRepeatNumTotal, NumTrainsAtLoc, Ptr1->Location,
true, AnalysisError, MaxNumberOfSameDirections);
17132 throw Exception(ServiceAndRepeatNumTotalOutput.c_str());
17136 AnsiString Asterisk =
"";
17137 if(MaxNumberOfSameDirections >= NumPlats)
17142 TTFile3 << Asterisk << Ptr1->Location <<
"," << NumPlats <<
"," << NumTrainsAtLoc <<
"," << ServiceAndRepeatNumTotalOutput <<
'\n';
17143 ArrivalsPrinted =
true;
17144 ServiceAndRepeatNumTotal =
"";
17146 if(Ptr2 == LocServiceTimesVector.end())
17150 if(Ptr2->Location != Ptr1->Location)
17155 if(Ptr2 == LocServiceTimesVector.end())
17161 if(!ArrivalsPrinted)
17163 TTFile3 <<
"Nothing to report for arrivals";
17168 SequenceLog +=
"7\n";
17173 Ptr1 = LocServiceTimesVector.begin();
17175 while(Ptr2 != LocServiceTimesVector.end())
17177 while(Ptr2->Location == Ptr1->Location)
17180 if(Ptr2 == LocServiceTimesVector.end())
17187 if(Ptr2 != LocServiceTimesVector.end())
17194 TTFile3 <<
"Departure & pass analysis: an asterisk means that the number of same exit code departures and passes is equal to or greater than the number of platforms.\n";
17195 TTFile3 <<
"If the total number of departures and passes at the same time exceeds the number of platforms the 'Trains present at location analysis' will show an asterisk.\n\n";
17196 MinuteString =
" minutes";
17197 AnsiString ServiceAndRepeatNumTotal =
"", ServiceAndRepeatNumTotalOutput =
"";
17200 MinuteString =
" minute";
17202 TTFile3 <<
"Location,Number of,Number of,Services departing within " << AnsiString(DepRange) << MinuteString <<
" with their departure times and exit codes\n";
17203 TTFile3 <<
",Platforms,Trains\n\n";
17205 Ptr1 = LocServiceTimesVector.begin();
17207 while(Ptr2 != LocServiceTimesVector.end())
17209 PreviousService =
"";
17210 NumTrainsAtLoc = 0;
17211 ServiceAndRepeatNumTotal =
"";
17213 NumPlatsAtThisLocCalculated =
false;
17215 while((Ptr2->Location != Ptr1->Location) || ((Ptr1->Location ==
"") && (Ptr2->Location ==
"")))
17217 PreviousService =
"";
17218 NumTrainsAtLoc = 0;
17219 ServiceAndRepeatNumTotal =
"";
17221 NumPlatsAtThisLocCalculated =
false;
17225 if(Ptr2 == LocServiceTimesVector.end())
17230 if(Ptr2 == LocServiceTimesVector.end())
17234 while(Ptr2->Location == Ptr1->Location)
17236 PreviousService =
"";
17237 NumTrainsAtLoc = 0;
17238 ServiceAndRepeatNumTotal =
"";
17239 BasicTime = Ptr1->DepTime;
17240 if((Ptr1->Location ==
"") && (Ptr2->Location ==
""))
17244 while(!
WithinTimeRange(3, BasicTime, Ptr2->DepTime, DepRange) || ((Ptr1->DepTime ==
"") && (Ptr2->DepTime ==
"")))
17246 BasicTime = Ptr2->DepTime;
17249 if(Ptr2 == LocServiceTimesVector.end())
17253 if(Ptr2->Location != Ptr1->Location)
17258 if(Ptr2 == LocServiceTimesVector.end())
17262 if(Ptr2->Location != Ptr1->Location)
17268 if((Ptr1->DepTime ==
"") && (Ptr2->DepTime ==
""))
17272 if(!NumPlatsAtThisLocCalculated)
17275 NumPlatsAtThisLocCalculated =
true;
17277 if(Ptr1->ServiceAndRepeatNum != PreviousService)
17279 if(ServiceAndRepeatNumTotal ==
"")
17281 ServiceAndRepeatNumTotal = Ptr1->ServiceAndRepeatNum +
"," + Ptr1->DepTime;
17282 NumTrainsAtLoc = 1;
17286 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr1->ServiceAndRepeatNum +
"," + Ptr1->DepTime;
17289 PreviousService = Ptr2->ServiceAndRepeatNum;
17290 if(ServiceAndRepeatNumTotal ==
"")
17292 ServiceAndRepeatNumTotal = Ptr2->ServiceAndRepeatNum +
"," + Ptr2->DepTime;
17293 NumTrainsAtLoc = 1;
17297 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr2->ServiceAndRepeatNum +
"," + Ptr2->DepTime;
17301 if((Ptr2 == LocServiceTimesVector.end()) || (Ptr2->Location != Ptr1->Location) || (!
WithinTimeRange(5, BasicTime, Ptr2->DepTime, DepRange)))
17303 int MaxNumberOfSameDirections = 0;
17304 ServiceAndRepeatNumTotalOutput =
ConsolidateSARNTArrDep(3, ServiceAndRepeatNumTotal, NumTrainsAtLoc, Ptr1->Location,
false, AnalysisError, MaxNumberOfSameDirections);
17309 throw Exception(ServiceAndRepeatNumTotalOutput.c_str());
17313 AnsiString Asterisk =
"";
17314 if(MaxNumberOfSameDirections >= NumPlats)
17319 TTFile3 << Asterisk << Ptr1->Location <<
"," << NumPlats <<
"," << NumTrainsAtLoc <<
"," << ServiceAndRepeatNumTotalOutput <<
'\n';
17320 DeparturesPrinted =
true;
17321 ServiceAndRepeatNumTotal =
"";
17323 if(Ptr2 == LocServiceTimesVector.end())
17327 if(Ptr2->Location != Ptr1->Location)
17332 if(Ptr2 == LocServiceTimesVector.end())
17338 if(!DeparturesPrinted)
17340 TTFile3 <<
"Nothing to report for departures";
17345 SequenceLog +=
"8\n";
17352 Ptr1 = LocServiceTimesVector.begin();
17354 while(Ptr2 != LocServiceTimesVector.end())
17356 while(Ptr2->Location == Ptr1->Location)
17359 if(Ptr2 == LocServiceTimesVector.end())
17366 if(Ptr2 != LocServiceTimesVector.end())
17373 TTFile3 <<
"Trains present at location analysis: an asterisk means that the number of trains at the location is greater than the number of platforms.\n\n";
17374 TTFile3 <<
"Location,Number of,Number of,Time,Services at the location at that time\n";
17375 TTFile3 <<
",Platforms,Trains,\n\n";
17376 AnsiString ServiceAndRepeatNumTotal =
"", ServiceAndRepeatNumTotalOutput =
"";
17377 Ptr1 = LocServiceTimesVector.begin();
17379 while(Ptr2 != LocServiceTimesVector.end())
17381 PreviousService =
"";
17382 ServiceAndRepeatNumTotal =
"";
17383 NumTrainsAtLoc = 0;
17385 NumPlatsAtThisLocCalculated =
false;
17387 while((Ptr2->Location != Ptr1->Location) || ((Ptr1->Location ==
"") && (Ptr2->Location ==
"")))
17389 PreviousService =
"";
17390 ServiceAndRepeatNumTotal =
"";
17391 NumTrainsAtLoc = 0;
17393 NumPlatsAtThisLocCalculated =
false;
17397 if(Ptr2 == LocServiceTimesVector.end())
17402 if(Ptr2 == LocServiceTimesVector.end())
17406 while(Ptr2->Location == Ptr1->Location)
17408 if(Ptr1->FrhMarker ==
"Frh")
17411 Ptr1->FrhMarker =
"FrhCounted";
17413 PreviousService =
"";
17414 NumTrainsAtLoc = 0;
17415 ServiceAndRepeatNumTotal =
"";
17416 if((Ptr1->Location ==
"") && (Ptr2->Location ==
""))
17420 while((Ptr2->AtLocTime != Ptr1->AtLocTime) || ((Ptr1->AtLocTime ==
"") && (Ptr2->AtLocTime ==
"")))
17423 if(Ptr1->FrhMarker ==
"Frh")
17426 Ptr1->FrhMarker =
"FrhCounted";
17429 if(Ptr2 == LocServiceTimesVector.end())
17433 if(Ptr2->Location != Ptr1->Location)
17438 if(Ptr2 == LocServiceTimesVector.end())
17442 if(Ptr2->Location != Ptr1->Location)
17446 while(Ptr2->AtLocTime == Ptr1->AtLocTime)
17448 if((Ptr1->AtLocTime ==
"") && (Ptr2->AtLocTime ==
""))
17452 if(!NumPlatsAtThisLocCalculated)
17455 NumPlatsAtThisLocCalculated =
true;
17457 if(Ptr1->ServiceAndRepeatNum != PreviousService)
17459 if(ServiceAndRepeatNumTotal ==
"")
17461 ServiceAndRepeatNumTotal = Ptr1->ServiceAndRepeatNum;
17462 NumTrainsAtLoc = 1;
17466 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr1->ServiceAndRepeatNum;
17469 PreviousService = Ptr2->ServiceAndRepeatNum;
17470 if(ServiceAndRepeatNumTotal ==
"")
17472 ServiceAndRepeatNumTotal = Ptr2->ServiceAndRepeatNum;
17473 NumTrainsAtLoc = 1;
17477 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr2->ServiceAndRepeatNum;
17480 if(Ptr1->FrhMarker ==
"Frh")
17483 Ptr1->FrhMarker =
"FrhCounted";
17486 if((Ptr2 == LocServiceTimesVector.end()) || (Ptr2->Location != Ptr1->Location) || (Ptr2->AtLocTime != Ptr1->AtLocTime))
17490 ServiceAndRepeatNumTotalOutput =
ConsolidateSARNTAtLoc(1, ServiceAndRepeatNumTotal, NumTrainsAtLoc);
17492 if((NumTrainsAtLoc > 1) && ((FrhCount < NumTrainsAtLoc) || (FrhCount != LastFrhCount)))
17494 AnsiString Asterisk =
"";
17495 if(NumTrainsAtLoc > NumPlats)
17502 TTFile3 << Asterisk << Ptr1->Location <<
"," << NumPlats <<
"," << NumTrainsAtLoc <<
"," << Ptr1->AtLocTime <<
"," << ServiceAndRepeatNumTotalOutput <<
'\n';
17504 else if(FrhCount == 1)
17506 TTFile3 << Asterisk << Ptr1->Location <<
"," << NumPlats <<
"," << NumTrainsAtLoc <<
"," << Ptr1->AtLocTime <<
" (1 remains here)," << ServiceAndRepeatNumTotalOutput <<
'\n';
17510 TTFile3 << Asterisk << Ptr1->Location <<
"," << NumPlats <<
"," << NumTrainsAtLoc <<
"," << Ptr1->AtLocTime <<
" (" << FrhCount <<
" remain here)," << ServiceAndRepeatNumTotalOutput <<
'\n';
17512 LastFrhCount = FrhCount;
17513 PreviousServiceAndRepeatNumTotalOutput = ServiceAndRepeatNumTotalOutput;
17514 AtLocsPrinted =
true;
17515 ServiceAndRepeatNumTotal =
"";
17518 if(Ptr2 == LocServiceTimesVector.end())
17522 if(Ptr2->Location != Ptr1->Location)
17527 if(Ptr2 == LocServiceTimesVector.end())
17535 TTFile3 <<
"Nothing to report for trains at locations";
17540 SequenceLog +=
"9\n";
17570 TTrainDataEntry SingleServiceEntry, PartServiceEntry, NewPartServiceEntry, TempEntry;
17575 TTFile3 <<
"Train direction analysis - consisting of train facing directions on creation and possible missing or questionable changes of direction:\n\n";
17576 for(
unsigned int x = 0; x < TrainDataVectorCopy.size(); x++)
17584 if((AV.at(0).Command ==
"Snt") || (AV.at(0).Command ==
"Snt-sh"))
17586 SingleServiceEntry = TDE;
17588 for(
unsigned int y = 0; y < SSAV.size(); y++)
17590 if((SSAV.at(y).Command ==
"Fjo") || (SSAV.at(y).Command ==
"Frh") || (SSAV.at(y).Command ==
"Fer") || (SSAV.at(y).Command ==
"Frh-sh"))
17592 SingleServiceVector.push_back(SingleServiceEntry);
17595 else if((SSAV.at(y).Command ==
"fsp") || (SSAV.at(y).Command ==
"rsp"))
17597 PartServiceEntry = TDE;
17599 for(
unsigned int z = 0; z <= y; z++)
17604 PartServiceEntry.
ActionVector.at(z).Command =
"chr-sp";
17605 PartServiceEntry.
ActionVector.at(z).OtherHeadCode = PartServiceEntry.
ActionVector.at(z).LinkedTrainEntryPtr->ServiceReference;
17608 PartServiceVector.push_back(PartServiceEntry);
17609 if(SSAV.at(y).Command ==
"fsp")
17611 SSAV.at(y).Command =
"Front split - original service continues below";
17612 SSAV.at(y).OtherHeadCode =
"";
17614 if(SSAV.at(y).Command ==
"rsp")
17616 SSAV.at(y).Command =
"Rear split - original service continues below";
17617 SSAV.at(y).OtherHeadCode =
"";
17621 else if(SSAV.at(y).Command ==
"Fns")
17623 SSAV.at(y).Command =
"chr-Fns";
17624 SSAV.at(y).OtherHeadCode = SSAV.at(y).LinkedTrainEntryPtr->ServiceReference;
17625 PartServiceVector.push_back(SingleServiceEntry);
17628 else if(SSAV.at(y).Command ==
"Fns-sh")
17630 SSAV.at(y).Command =
"chr-Fns-sh";
17631 SSAV.at(y).OtherHeadCode = SSAV.at(y).NonRepeatingShuttleLinkEntryPtr->ServiceReference;
17632 SSAV.at(y).NonRepeatingShuttleLinkHeadCode =
"";
17633 PartServiceVector.push_back(SingleServiceEntry);
17636 else if(SSAV.at(y).Command ==
"F-nshs")
17638 SSAV.at(y).Command =
"chr-F-nshs";
17639 SSAV.at(y).OtherHeadCode = SSAV.at(y).LinkedTrainEntryPtr->ServiceReference;
17640 SSAV.at(y).NonRepeatingShuttleLinkHeadCode =
"";
17641 PartServiceVector.push_back(SingleServiceEntry);
17647 SequenceLog +=
"10\n";
17651 AnsiString NextRef;
17652 while(!PartServiceVector.empty())
17654 PartServiceEntry = PartServiceVector.at(0);
17655 for(
unsigned int y = 0; y < PartServiceEntry.
ActionVector.size(); y++)
17657 if(PartServiceEntry.
ActionVector.at(y).Command.SubString(1,3) ==
"chr")
17659 NextRef = PartServiceEntry.
ActionVector.at(y).OtherHeadCode;
17663 bool FinishType =
true, FoundFlag =
false;
17670 for(
unsigned int y = 1; y < TempEntry.
ActionVector.size(); y++)
17674 PartServiceVector.at(0).ActionVector.push_back(TempEntry.
ActionVector.at(y));
17678 PartServiceVector.at(0).ActionVector.push_back(TempEntry.
ActionVector.at(y));
17684 PartServiceVector.at(0).ActionVector.push_back(TempEntry.
ActionVector.at(y));
17685 SingleServiceVector.push_back(PartServiceVector.at(0));
17686 PartServiceVector.erase(&PartServiceVector.at(0));
17691 NewPartServiceEntry = PartServiceVector.at(0);
17695 PartServiceVector.push_back(NewPartServiceEntry);
17698 TempEntry.
ActionVector.at(y).Command =
"Front split - original service continues below";
17703 TempEntry.
ActionVector.at(y).Command =
"Rear split - original service continues below";
17706 PartServiceVector.at(0).ActionVector.push_back(TempEntry.
ActionVector.at(y));
17708 else if(TempEntry.
ActionVector.at(y).Command ==
"Fns")
17711 NextRef = TempEntry.
ActionVector.at(y).LinkedTrainEntryPtr->ServiceReference;
17713 PartServiceVector.at(0).ActionVector.push_back(TempEntry.
ActionVector.at(y));
17716 else if(TempEntry.
ActionVector.at(y).Command ==
"Fns-sh")
17719 TempEntry.
ActionVector.at(y).OtherHeadCode = TempEntry.
ActionVector.at(y).NonRepeatingShuttleLinkEntryPtr->ServiceReference;
17720 TempEntry.
ActionVector.at(y).NonRepeatingShuttleLinkHeadCode =
"";
17721 NextRef = TempEntry.
ActionVector.at(y).NonRepeatingShuttleLinkEntryPtr->ServiceReference;
17722 PartServiceVector.at(0).ActionVector.push_back(TempEntry.
ActionVector.at(y));
17725 else if(TempEntry.
ActionVector.at(y).Command ==
"F-nshs")
17729 TempEntry.
ActionVector.at(y).NonRepeatingShuttleLinkHeadCode =
"";
17730 NextRef = TempEntry.
ActionVector.at(y).LinkedTrainEntryPtr->ServiceReference;
17731 PartServiceVector.at(0).ActionVector.push_back(TempEntry.
ActionVector.at(y));
17739 SequenceLog += +
"11\n";
17740 throw Exception(
"Unable to find service reference " + NextRef +
" Last ref checked = " + TempEntry.
ServiceReference);
17744 if(!PartServiceVector.empty())
17746 SequenceLog +=
"12\n";
17747 throw Exception(
"PartServiceVector should be empty here - size = " + PartServiceVector.size());
17749 SequenceLog +=
"13\n";
17794 bool BufferFacingUnReportedFlag =
true;
17795 for(
unsigned int x = 0; x < SingleServiceVector.size(); x++)
17801 SequenceLog +=
"13a\n";
17802 throw Exception(
"Repeat entry present in SingleServiceVector at position " + x);
17805 if((AV.at(0).Command ==
"Snt") || (AV.at(0).Command ==
"Snt-sh"))
17807 bool BufferFlag =
false;
17808 int FrontTVPos = AV.at(0).FrontStartOrRepeatDigits;
17809 int RearTVPos = AV.at(0).RearStartOrRepeatMins;
17810 AnsiString FrontLocName = AV.at(0).LocationName;
17811 int NextEntryPos, NextExitPos;
17814 if(ThisElement.
Conn[0] == RearTVPos)
17818 else if(ThisElement.
Conn[1] == RearTVPos)
17822 else if(ThisElement.
Conn[2] == RearTVPos)
17826 else if(ThisElement.
Conn[3] == RearTVPos)
17838 if(ThisElement.
Conn[ThisExitPos] == -1)
17840 SequenceLog =
"13b\n";
17841 throw Exception(
"ThisElement connects to -1 for " + TDE.
ServiceReference);
17844 NextEntryPos = ThisElement.
ConnLinkPos[ThisExitPos];
17845 if((NextElement.
TrackType ==
Points) && ((NextEntryPos == 0) || (NextEntryPos == 2)))
17847 BufferFlag =
false;
17852 BufferFlag =
false;
17857 BufferFlag =
false;
17865 else if((NextElement.
TrackType ==
Points) && ((NextEntryPos == 1) || (NextEntryPos == 3)))
17867 ThisElement = NextElement;
17873 if(NextEntryPos == 0)
17877 else if(NextEntryPos == 1)
17881 else if(NextEntryPos == 2)
17885 else if(NextEntryPos == 3)
17890 ThisElement = NextElement;
17891 ThisExitPos = NextExitPos;
17896 if(BufferFacingUnReportedFlag)
17898 TTFile3 <<
"Train facing direction on creation analysis:-\n\n";
17899 BufferFacingUnReportedFlag =
false;
17901 TTFile3 <<
"Service " + TDE.
ServiceReference +
" facing buffers on creation\n";
17905 if(BufferFacingUnReportedFlag)
17907 TTFile3 <<
"Nothing to report for train facing directions\n\n";
17913 SequenceLog +=
"13c\n";
17916 AnsiString LocationNameToBeChecked =
"";
17917 bool MissingcdtUnreportedFlag =
true;
17919 for(
unsigned int x = 0; x < SingleServiceVector.size(); x++)
17922 unsigned int y = 0;
17923 int FirstInstance = 9999, SecondInstance = 9999;
17924 bool FullBreak =
false;
17925 MarkerList.clear();
17932 while((y < TDEntry.
ActionVector.size()) && !FullBreak)
17941 LocationNameToBeChecked = TDEntry.
ActionVector.at(y).LocationName;
17943 for(
unsigned int z = y; z < TDEntry.
ActionVector.size(); z++)
17948 (AVEntry.
Command ==
"Frh-sh"))
17963 for(
unsigned int a = z; a < TDEntry.
ActionVector.size(); a++)
17969 if(TDEntry.
ActionVector.at(a).LocationName == LocationNameToBeChecked)
17971 SecondInstance = a;
17973 for(
unsigned int b = 0; b < TDEntry.
ActionVector.size(); b++)
17975 if(TDEntry.
ActionVector.at(b).Command.SubString(1,3) ==
"chr")
17977 Sequence = Sequence + AnsiString(
" -> ") + TDEntry.
ActionVector.at(b).OtherHeadCode;
17980 if(MissingcdtUnreportedFlag)
17982 TTFile3 <<
"Possibly missing changes of direction - these will be missing unless the service travels in a loop back to the locations marked:-\n\n";
17984 TTFile3 << LocationNameToBeChecked <<
" is listed twice with no direction change between in service sequence: " << Sequence <<
"\n\n";
17985 MarkerList.push_back(FirstInstance);
17986 MarkerList.push_back(SecondInstance);
17988 MissingcdtUnreportedFlag =
false;
17999 if(MissingcdtUnreportedFlag)
18001 TTFile3 <<
"Nothing to report for missing changes of direction\n\n";
18007 SequenceLog +=
"14\n";
18016 typedef std::list<AnsiString> TLocList;
18017 TLocList BackwardList, ForwardList;
18018 bool IntroLineNeeded =
true;
18019 for(
unsigned int x = 0; x < SingleServiceVector.size(); x++)
18021 unsigned int cdtPosition = 9999;
18022 AnsiString cdtLocation =
"";
18023 bool FoundSameName =
false;
18024 MarkerList.clear();
18026 for(
unsigned int y = 0; y < TDEntry.
ActionVector.size(); y++)
18029 BackwardList.clear();
18030 ForwardList.clear();
18034 (AVEntry.
Command ==
"Frh-sh"))
18036 if(MarkerList.empty())
18043 for(
unsigned int b = 0; b < TDEntry.
ActionVector.size(); b++)
18045 if(TDEntry.
ActionVector.at(b).Command.SubString(1,3) ==
"chr")
18047 Sequence = Sequence + AnsiString(
" -> ") + TDEntry.
ActionVector.at(b).OtherHeadCode;
18051 if(IntroLineNeeded)
18053 TTFile3 <<
"Questionable change of direction analysis.\n\n";
18054 TTFile3 <<
"For marked changes of direction there are no same-name locations listed both above and below.\n";
18055 TTFile3 <<
"These changes of direction are probably valid for movements to and from depots but all should be checked to\n";
18056 TTFile3 <<
"make sure that none has been included incorrectly:\n\n";
18057 IntroLineNeeded =
false;
18059 TTFile3 <<
"Service sequence " << Sequence <<
" contains questionable changes of direction:-\n\n";
18071 for(
int z = y - 1; z >= 0; z--)
18074 if(AVEntry2.
Command ==
"cdt")
18083 BackwardList.sort();
18084 BackwardList.unique();
18085 for(
unsigned int z = y + 1; z < TDEntry.
ActionVector.size(); z++)
18099 ForwardList.sort();
18100 ForwardList.unique();
18101 FoundSameName =
false;
18103 if(!BackwardList.empty() && !ForwardList.empty())
18105 for(TLocList::iterator BLIt = BackwardList.begin(); BLIt != BackwardList.end(); BLIt++)
18107 for(TLocList::iterator FLIt = ForwardList.begin(); FLIt != ForwardList.end(); FLIt++)
18111 FoundSameName =
true;
18118 MarkerList.push_back(cdtPosition);
18122 if(IntroLineNeeded)
18124 TTFile3 <<
"Nothing to report for questionable changes of direction\n\n";
18140 SequenceLog +=
"15\n";
18146 catch(
const Exception &e)
18148 AnsiString TTErrorFileName =
"Analysis Error.txt";
18149 TTErrorFileName = CurDir +
"\\Formatted timetables\\" + TTErrorFileName;
18150 std::ofstream TTError(TTErrorFileName.c_str());
18153 ShowMessage(
"Analysis error file failed to open - can't be created");
18157 AnsiString TimeNow = TDateTime::CurrentDateTime().FormatString(
"dd-mm-yyyy hh.nn.ss");
18158 TTError << TimeNow.c_str() <<
'\n' << ArrRange <<
'\n' << ArrChecked <<
'\n' << DepRange <<
'\n' <<
18159 DepChecked <<
'\n' << AtLocChecked <<
'\n' << SequenceLog <<
'\n' << AnsiString(e.Message);
18162 ShowMessage(
"Error in Conflict Analysis: A file called 'Analysis Error.txt' has been created in your Formatted timetables folder. Please send this file together with your railway and timetable files to railwayfeedback@gmail.com for investigation - many thanks");
18172 if((SSVectorNumber < 0) || ((
unsigned int)SSVectorNumber >= SingleServiceVector.size()))
18174 throw Exception(
"SSVectorNumber out of range, = " + AnsiString(SSVectorNumber) +
", Vector size = " + SingleServiceVector.size());
18176 TTrainDataEntry SingleService = SingleServiceVector.at(SSVectorNumber);
18178 VecFile <<
",Initial service reference " << SingleService.
ServiceReference +
'\n';
18179 AnsiString Marker =
"";
18180 for(
unsigned int x = 0; x < SingleService.
ActionVector.size(); x++)
18183 for(
TNumListIterator MLIt = MarkerList.begin(); MLIt != MarkerList.end(); MLIt++)
18185 if(
int(x) == *MLIt)
18196 VecFile << Marker << AnsiString(AVE.
EventTime.TimeString()) <<
' ' << AVE.
Command <<
' ' << RearID <<
' ' << FrontID <<
'\n';
18202 VecFile << Marker << AnsiString(AVE.
EventTime.TimeString()) <<
' ' << AVE.
Command <<
' ' << RearID <<
' ' << FrontID <<
' ' << AVE.
OtherHeadCode <<
'\n';
18215 if(AVE.
Command.SubString(1,3) ==
"chr")
18224 AVE.
Command =
"Change of service to ";
18226 if(AVE.
Command.SubString(5, AVE.
Command.Length() - 4) ==
"Fns-sh")
18228 AVE.
Command =
"Change to shuttle finishing service";
18230 if(AVE.
Command.SubString(5, AVE.
Command.Length() - 4) ==
"F-nshs")
18253 VecFile << Marker << AnsiString(AVE.
EventTime.TimeString()) <<
' ' <<
"Pass" <<
' ' << AVE.
LocationName <<
'\n';
18257 AnsiString ListOfExits =
"";
18262 VecFile << Marker << AnsiString(AVE.
EventTime.TimeString()) <<
" Fer " << ListOfExits <<
'\n';
18266 VecFile << Marker <<
"Frh" <<
'\n';
18281 for(
unsigned int x = 0; x < Vector.size(); x++)
18285 if(Vector.at(x).ActionVector.at(Vector.at(x).ActionVector.size() - 1).FormatType ==
Repeat)
18287 TActionVectorEntry AVE = Vector.at(x).ActionVector.at(Vector.at(x).ActionVector.size() - 2);
18290 FinishType =
false;
18295 TActionVectorEntry AVE = Vector.at(x).ActionVector.at(Vector.at(x).ActionVector.size() - 1);
18298 FinishType =
false;
18303 return(Vector.at(x));
18307 return(Vector.at(Vector.size() - 1));
18316 if((Time1 ==
"") || (Time2 ==
""))
18321 int Mins = Time1.SubString(4,2).ToInt();
18322 int Hours = Time1.SubString(1,2).ToInt();
18323 int Time1Mins = (Hours * 60) + Mins;
18324 Mins = Time2.SubString(4,2).ToInt();
18325 Hours = Time2.SubString(1,2).ToInt();
18326 int Time2Mins = (Hours * 60) + Mins;
18327 if(abs(Time1Mins - Time2Mins) <= MinuteRange)
18339 bool &AnalysisError,
int &MaxNumberOfSameDirections)
18346 AnsiString Output =
"", OneService =
"", TempStr1 =
"", TempStr2 =
"";
18348 std::list<AnsiString> ServiceList;
18350 bool EvenComma =
false;
18351 for(
int x = 1; x <= Input.Length(); x++)
18353 TempStr1 = Input[x];
18354 if(TempStr1 == AnsiString(
',') && EvenComma)
18360 TempStr2 += Input[x];
18362 if(TempStr1 == AnsiString(
','))
18364 EvenComma = !EvenComma;
18368 while(TempStr2.Length() > 0)
18370 SCPos = TempStr2.Pos(
';');
18373 OneService = TempStr2.SubString(1, SCPos - 1);
18374 ServiceList.push_back(OneService);
18375 TempStr2 = TempStr2.SubString(SCPos + 1, TempStr2.Length() - SCPos);
18379 ServiceList.push_back(TempStr2);
18383 ServiceList.sort();
18384 ServiceList.unique();
18385 NumTrainsAtLoc = ServiceList.size();
18388 int DirectionMarker = 0;
18390 std::list<AnsiString>::iterator SLIt, SLIt1, SLIt2, SLIt3;
18392 for(SLIt = ServiceList.begin(); SLIt != ServiceList.end(); SLIt++)
18394 *SLIt = *SLIt +
"&0";
18396 SLIt3 = ServiceList.end();
18398 AnsiString ServiceRef1, ServiceRef2, AnsiTime1, AnsiTime2, RepeatInfo1, RepeatInfo2;
18399 int AmpersandPos, SpacePos, CommaPos1, CommaPos2, RepeatNum1, RepeatNum2;
18400 TAllServiceCallingLocsMap::iterator ASCLIt1, ASCLIt2;
18402 MaxNumberOfSameDirections = 0;
18403 int SameDirectionCount = 0;
18405 for(std::list<AnsiString>::iterator SLIt1 = ServiceList.begin(); SLIt1 != SLIt3; SLIt1++)
18409 if(SLIt1->SubString(SLIt1->Length() - 1, 2) != AnsiString(
"&0"))
18415 CommaPos1 = SLIt1->Pos(
',');
18416 ServiceRef1 = SLIt1->SubString(1, CommaPos1 - 1);
18418 SpacePos = ServiceRef1.Pos(
' ');
18422 RepeatInfo1 = ServiceRef1.SubString(SpacePos + 2, ServiceRef1.Length() - SpacePos - 2);
18423 ServiceRef1 = ServiceRef1.SubString(1, SpacePos - 1);
18424 if(RepeatInfo1[1] ==
'F')
18430 SpacePos = RepeatInfo1.Pos(
' ');
18431 RepeatNum1 = RepeatInfo1.SubString(SpacePos + 1, RepeatInfo1.Length() - SpacePos).ToInt();
18434 AnsiTime1 = SLIt1->SubString(CommaPos1 + 1, SLIt1->Length() - CommaPos1);
18436 AmpersandPos = AnsiTime1.Pos(
'&');
18437 AnsiTime1 = AnsiTime1.SubString(1, AmpersandPos - 1);
18442 throw Exception(
"ASCLIt1 Error in " + Input);
18444 ServiceCallingLocsList1 = ASCLIt1->second;
18445 AmpersandPos = SLIt1->Pos(
'&');
18446 *SLIt1 = SLIt1->SubString(1, AmpersandPos);
18447 *SLIt1 = *SLIt1 + AnsiString(++DirectionMarker);
18449 SameDirectionCount = 1;
18450 for(SLIt2 = SLIt; SLIt2 != ServiceList.end(); SLIt2++)
18452 CommaPos2 = SLIt2->Pos(
',');
18453 ServiceRef2 = SLIt2->SubString(1, CommaPos2 - 1);
18455 SpacePos = ServiceRef2.Pos(
' ');
18459 RepeatInfo2 = ServiceRef2.SubString(SpacePos + 2, ServiceRef2.Length() - SpacePos - 2);
18460 ServiceRef2 = ServiceRef2.SubString(1, SpacePos - 1);
18461 if(RepeatInfo2[1] ==
'F')
18467 SpacePos = RepeatInfo2.Pos(
' ');
18468 RepeatNum2 = RepeatInfo2.SubString(SpacePos + 1, RepeatInfo2.Length() - SpacePos).ToInt();
18471 AnsiTime2 = SLIt2->SubString(CommaPos2 + 1, SLIt2->Length() - CommaPos2);
18473 AmpersandPos = AnsiTime2.Pos(
'&');
18474 AnsiTime2 = AnsiTime2.SubString(1, AmpersandPos - 1);
18479 throw Exception(
"ASCLIt2 Error in " + Input);
18481 ServiceCallingLocsList2 = ASCLIt2->second;
18483 if(
SameDirection(0, ServiceRef1, ServiceRef2, AnsiTime1, AnsiTime2, RepeatNum1, RepeatNum2, ServiceCallingLocsList1, ServiceCallingLocsList2, Location, Arrival))
18485 int AmpersandPos = SLIt2->Pos(
'&');
18486 *SLIt2 = SLIt2->SubString(1, AmpersandPos);
18487 *SLIt2 = *SLIt2 + AnsiString(DirectionMarker);
18488 SameDirectionCount++;
18491 if(SameDirectionCount > MaxNumberOfSameDirections)
18493 MaxNumberOfSameDirections = SameDirectionCount;
18498 if(SLIt3->SubString(SLIt3->Length() - 1, 2) == AnsiString(
"&0"))
18501 AmpersandPos = SLIt3->Pos(
'&');
18502 *SLIt3 = SLIt3->SubString(1, AmpersandPos);
18503 *SLIt3 = *SLIt3 + AnsiString(++DirectionMarker);
18506 for(SLIt = ServiceList.begin(); SLIt != ServiceList.end(); SLIt++)
18509 AmpersandPos = SLIt->Pos(
'&');
18510 AnsiString DirectionMarkerString = SLIt->SubString(AmpersandPos + 1, SLIt->Length() - AmpersandPos);
18511 AnsiString ServiceWithoutMarker = SLIt->SubString(1, AmpersandPos - 1);
18512 DirectionMarker = DirectionMarkerString.ToInt();
18513 AnsiString DirectionSuffix =
"";
18515 if(DirectionMarker < 27)
18517 c = 64 + DirectionMarker;
18518 DirectionSuffix =
"," + AnsiString(c);
18520 else if(DirectionMarker < 53)
18522 c = 65 + DirectionMarker - 27;
18523 DirectionSuffix =
",A" + AnsiString(c);
18527 DirectionSuffix =
",?";
18529 *SLIt = ServiceWithoutMarker + DirectionSuffix;
18532 for(SLIt = ServiceList.begin(); SLIt != ServiceList.end(); SLIt++)
18534 Output = Output + *SLIt +
",";
18536 if(Output.Length() > 0)
18538 Output = Output.SubString(1, Output.Length() - 1);
18544 catch(
const Exception &e)
18546 AnalysisError =
true;
18558 AnsiString InternalInput = Input, Output =
"", OneService =
"";
18560 std::list<AnsiString> ServiceList;
18562 while(InternalInput.Length() > 0)
18564 CommaPos = InternalInput.Pos(
',');
18567 OneService = InternalInput.SubString(1, CommaPos - 1);
18568 ServiceList.push_back(OneService);
18569 InternalInput = InternalInput.SubString(CommaPos + 1, InternalInput.Length() - CommaPos);
18573 ServiceList.push_back(InternalInput);
18574 InternalInput =
"";
18578 ServiceList.sort();
18579 ServiceList.unique();
18580 NumTrainsAtLoc = ServiceList.size();
18581 for(std::list<AnsiString>::iterator SLIt = ServiceList.begin(); SLIt != ServiceList.end(); SLIt++)
18583 Output = Output + *SLIt +
",";
18585 if(Output.Length() > 0)
18587 Output = Output.SubString(1, Output.Length() - 1);
18600 AnsiString(RepeatNum1) +
"," + AnsiString(RepeatNum2) +
"," + Location);
18602 std::list<AnsiString>::iterator LP1 = 0, LP2 = 0, ListPtr1 = 0, ListPtr2 = 0, LocPtr1 = 0, LocPtr2 = 0;
18607 bool LocFound =
false;
18608 AnsiString Ref1 = Ref1In, Ref2 = Ref2In;
18610 TDateTime FirstServiceTime;
18613 int Ref1Target = 0, Ref1Count = 0;
18614 int SlashPos = Ref1.Pos(
'/');
18617 Ref1Target = Ref1.SubString(SlashPos + 1, Ref1.Length() - SlashPos).ToInt();
18618 Ref1 = Ref1.SubString(1, SlashPos - 1);
18620 int Ref2Target = 0, Ref2Count = 0;
18621 SlashPos = Ref2.Pos(
'/');
18624 Ref2Target = Ref2.SubString(SlashPos + 1, Ref2.Length() - SlashPos).ToInt();
18625 Ref2 = Ref2.SubString(1, SlashPos - 1);
18627 for(ListPtr1 = List1.begin(); ListPtr1 != List1.end(); ListPtr1++)
18630 if((*ListPtr1) == Location)
18632 LocPtr1 = ListPtr1;
18635 if(ListPtr1->SubString(1, 3) ==
"%%%")
18637 AnsiString CDTTime = ListPtr1->SubString(4, 5);
18642 FirstServiceTime = TDateTime(-1);
18643 bool BreakFlag =
false;
18646 if(TDVIt->ServiceReference == Ref1)
18648 if(Ref1Target > Ref1Count)
18653 IncMinutes = TDVIt->ActionVector.back().RearStartOrRepeatMins;
18654 for(TActionVector::iterator AVIt = TDVIt->ActionVector.begin(); AVIt != TDVIt->ActionVector.end(); AVIt++)
18658 FirstServiceTime = AVIt->EventTime;
18664 FirstServiceTime = AVIt->ArrivalTime;
18670 FirstServiceTime = AVIt->DepartureTime;
18681 if(IncMinutes == -1)
18683 throw Exception(
"Failed to find service for ServiceRef1 in SameDirection " + Ref1In +
" " + Ref2In +
" " + Time1 +
" " + Time2 +
" " + AnsiString(RepeatNum1) +
" " + AnsiString(RepeatNum2) +
" " + Location);
18685 if(FirstServiceTime == TDateTime(-1))
18687 throw Exception(
"Failed to find first service time for ServiceRef1 in SameDirection " + Ref1In +
" " + Ref2In +
" " + Time1 +
" " + Time2 +
" " + AnsiString(RepeatNum1) +
" " + AnsiString(RepeatNum2) +
" " + Location);
18691 if(!Arrival && (Time1 == CDTTime))
18696 if(Arrival && (Time1 == CDTTime))
18700 if(Time1 > CDTTime)
18705 if(Time1 < CDTTime)
18718 for(ListPtr2 = List2.begin(); ListPtr2 != List2.end(); ListPtr2++)
18720 if((*ListPtr2) == Location)
18722 LocPtr2 = ListPtr2;
18725 if(ListPtr2->SubString(1, 3) ==
"%%%")
18727 AnsiString CDTTime = ListPtr2->SubString(4, 5);
18732 FirstServiceTime = TDateTime(-1);
18733 bool BreakFlag =
false;
18736 if(TDVIt->ServiceReference == Ref2)
18738 if(Ref2Target > Ref2Count)
18743 IncMinutes = TDVIt->ActionVector.back().RearStartOrRepeatMins;
18744 for(TActionVector::iterator AVIt = TDVIt->ActionVector.begin(); AVIt != TDVIt->ActionVector.end(); AVIt++)
18748 FirstServiceTime = AVIt->EventTime;
18754 FirstServiceTime = AVIt->ArrivalTime;
18760 FirstServiceTime = AVIt->DepartureTime;
18771 if(IncMinutes == -1)
18773 throw Exception(
"IncMinutes -1 for ServiceRef2 in SameDirection " + Ref1In +
" " + Ref2In +
" " + Time1 +
" " + Time2 +
" " + AnsiString(RepeatNum1) +
" " + AnsiString(RepeatNum2) +
" " + Location);
18775 if(FirstServiceTime == TDateTime(-1))
18777 throw Exception(
"First service time -1 for ServiceRef2 in SameDirection " + Ref1In +
" " + Ref2In +
" " + Time1 +
" " + Time2 +
" " + AnsiString(RepeatNum1) +
" " + AnsiString(RepeatNum2) +
" " + Location);
18781 if(!Arrival && (Time2 == CDTTime))
18786 if(Arrival && (Time2 == CDTTime))
18790 if(Time2 > CDTTime)
18795 if(Time2 < CDTTime)
18810 LP1 = List1.begin();
18812 for(ListPtr1 = LocPtr1; ListPtr1 != LP1; ListPtr1--)
18814 if(ListPtr1 == List1.begin())
18818 if(ListPtr1->SubString(1, 3) ==
"%%%")
18825 LP2 = List2.begin();
18827 for(ListPtr2 = LocPtr2; ListPtr2 != LP2; ListPtr2--)
18829 if(ListPtr2 == List2.begin())
18833 if(ListPtr2->SubString(1, 3) ==
"%%%")
18843 for(ListPtr1 = LP1; ListPtr1 != List1.end(); ListPtr1++)
18845 if(ListPtr1 == LocPtr1)
18849 if(ListPtr1->SubString(1, 3) ==
"%%%")
18853 for(ListPtr2 = LP2; ListPtr2 != List2.end(); ListPtr2++)
18855 if(ListPtr2 == LocPtr2)
18859 if(ListPtr2->SubString(1, 3) ==
"%%%")
18863 if((*ListPtr1) == (*ListPtr2))
18880 for(ListPtr1 = LP1; ListPtr1 != List1.end(); ListPtr1++)
18882 if(ListPtr1 == List1.end())
18886 if(ListPtr1->SubString(1, 3) ==
"%%%")
18890 for(ListPtr2 = LP2; ListPtr2 != List2.end(); ListPtr2++)
18892 if(ListPtr2 == List2.end())
18896 if(ListPtr2->SubString(1, 3) ==
"%%%")
18900 if((*ListPtr1) == (*ListPtr2))
18917 if(ExitList.empty())
18923 AnsiString ExitLocList =
"";
18926 unsigned int Counter = 0;
18927 for(
TNumListIterator ELIt = ExitList.begin(); ELIt != ExitList.end(); ELIt++)
18931 if(((Counter % 6) == 0) && (Counter < (ExitList.size() - 1)))
18933 ExitLocList +=
"\n";
18936 if(StartName ==
"")
18938 if(ExitList.size() == 1)
18942 return(
" at " + ID);
18947 if(ExitList.size() < 4)
18949 AllowedExits =
",\nallowable exit element(s): " + ExitLocList;
18954 AllowedExits =
",\nallowable exit element(s):\n" + ExitLocList;
18959 for(
TNumListIterator ELIT = ExitList.begin(); ELIT != ExitList.end(); ELIT++)
18964 if(ExitList.size() < 4)
18966 AllowedExits =
",\nallowable exit element(s): " + ExitLocList;
18971 AllowedExits =
",\nallowable exit element(s):\n" + ExitLocList;
18977 if(ExitList.size() < 4)
18979 AllowedExits =
",\nallowable exit element(s): " + ExitLocList;
18980 return(
" at " + StartName);
18984 AllowedExits =
",\nallowable exit element(s):\n" + ExitLocList;
18985 return(
" at " + StartName);
19025 AnsiString FormatStr =
"####0.0";
19026 AnsiString AvLateArrMins =
"";
19027 AnsiString AvEarlyArrMins =
"";
19028 AnsiString AvLatePassMins =
"";
19029 AnsiString AvEarlyPassMins =
"";
19030 AnsiString AvLateDepMins =
"";
19031 AnsiString AvLateExitMins =
"";
19032 AnsiString AvEarlyExitMins =
"";
19062 PerfFile <<
'\n' <<
'\n' <<
"***************************************";
19063 PerfFile <<
'\n' <<
'\n' <<
"Performance summary:" <<
'\n';
19075 PerfFile <<
LateArrivals <<
" late arrivals (average " << AvLateArrMins.c_str() <<
" min)" <<
'\n';
19079 PerfFile <<
LateArrivals <<
" late arrival (" << AvLateArrMins.c_str() <<
" min)" <<
'\n';
19087 PerfFile <<
EarlyArrivals <<
" early arrivals (average " << AvEarlyArrMins.c_str() <<
" min)" <<
'\n';
19091 PerfFile <<
EarlyArrivals <<
" early arrival (" << AvEarlyArrMins.c_str() <<
" min)" <<
'\n';
19099 PerfFile <<
OnTimePasses <<
" on-time passes" <<
'\n';
19107 PerfFile <<
LatePasses <<
" late passes (average " << AvLatePassMins.c_str() <<
" min)" <<
'\n';
19111 PerfFile <<
LatePasses <<
" late pass (" << AvLatePassMins.c_str() <<
" min)" <<
'\n';
19115 PerfFile <<
LatePasses <<
" late passes" <<
'\n';
19119 PerfFile <<
EarlyPasses <<
" early passes (average " << AvEarlyPassMins.c_str() <<
" min)" <<
'\n';
19123 PerfFile <<
EarlyPasses <<
" early pass (" << AvEarlyPassMins.c_str() <<
" min)" <<
'\n';
19127 PerfFile <<
EarlyPasses <<
" early passes" <<
'\n';
19132 PerfFile <<
OnTimeExits <<
" on-time exits" <<
'\n';
19136 PerfFile <<
OnTimeExits <<
" on-time exit" <<
'\n';
19140 PerfFile <<
LateExits <<
" late exits (average " << AvLateExitMins.c_str() <<
" min)" <<
'\n';
19144 PerfFile <<
LateExits <<
" late exit (" << AvLateExitMins.c_str() <<
" min)" <<
'\n';
19148 PerfFile <<
LateExits <<
" late exits" <<
'\n';
19152 PerfFile <<
EarlyExits <<
" early exits (average " << AvEarlyExitMins.c_str() <<
" min)" <<
'\n';
19156 PerfFile <<
EarlyExits <<
" early exit (" << AvEarlyExitMins.c_str() <<
" min)" <<
'\n';
19160 PerfFile <<
EarlyExits <<
" early exits" <<
'\n';
19165 PerfFile <<
OnTimeDeps <<
" on-time departures" <<
'\n';
19169 PerfFile <<
OnTimeDeps <<
" on-time departure" <<
'\n';
19173 PerfFile <<
LateDeps <<
" late departures (average " << AvLateDepMins.c_str() <<
" min)" <<
'\n';
19177 PerfFile <<
LateDeps <<
" late departure (" << AvLateDepMins.c_str() <<
" min)" <<
'\n';
19181 PerfFile <<
LateDeps <<
" late departures" <<
'\n';
19183 TDateTime TempExcessLCDownTime;
19197 if(TempExcessLCDownTime > TDateTime(0))
19203 AnsiString FormattedExcessLCDownMins = FormatFloat(FormatStr,
ExcessLCDownMins);
19207 PerfFile << FormattedExcessLCDownMins.c_str() <<
" excess minutes of level crossing barrier down time" <<
'\n';
19211 PerfFile <<
MissedStops <<
" missed stops" <<
'\n';
19215 PerfFile <<
MissedStops <<
" missed stop" <<
'\n';
19251 PerfFile <<
NumFailures <<
" train failures" <<
'\n';
19255 PerfFile <<
NumFailures <<
" train failure" <<
'\n';
19261 PerfFile <<
AvHoursIntValue <<
" hour mean time betweeen train failures" <<
'\n';
19265 PerfFile <<
AvHoursIntValue <<
" hours mean time betweeen train failures" <<
'\n';
19268 AnsiString AvLateMinsLocsNotReached =
"";
19274 if(LocsNotReached > 0)
19277 PerfFile << LocsNotReached <<
" locations that trains failed to reach (average lateness " << AvLateMinsLocsNotReached.c_str() <<
" min)" <<
'\n';
19281 PerfFile <<
SPADRisks <<
" SPAD risks" <<
'\n';
19285 PerfFile <<
SPADRisks <<
" SPAD risk" <<
'\n';
19297 PerfFile <<
Derailments <<
" derailments" <<
'\n';
19301 PerfFile <<
Derailments <<
" derailment" <<
'\n';
19311 PerfFile <<
'\n' <<
"***************************************" <<
'\n';
19313 bool DerailSPADFlag =
false, CrashFlag =
false;
19315 int OverallScorePercent = 100;
19316 int TotArrDepExit = 0;
19317 double TotLateMinsFactor = 1;
19318 double MissedStopAndSPADRiskFactor = 1;
19319 double NetNegFactor = 1;
19329 OverallScorePercent = 5;
19330 DerailSPADFlag =
true;
19334 OverallScorePercent = 0;
19337 if(OverallScorePercent == 100)
19339 if(TotArrDepExit > 0)
19341 TotLateMinsFactor =
19349 NetNegFactor = TotLateMinsFactor * MissedStopAndSPADRiskFactor;
19351 OverallScorePercent = 100 * NetNegFactor;
19354 if((TotArrDepExit > 0) || DerailSPADFlag || CrashFlag)
19357 AnsiString OneFailureString =
", though the failure would account for some poor performance";
19358 AnsiString TwoOrMoreFailureString =
", though the failures would account for some poor performance";
19359 AnsiString AddedString =
"";
19362 AddedString = OneFailureString;
19366 AddedString = TwoOrMoreFailureString;
19368 PerfFile <<
"\nOverall score: " << OverallScorePercent <<
"%\n";
19369 AnsiString Rating =
"";
19370 if(OverallScorePercent == 100)
19372 Rating =
"Perfect!";
19374 else if(OverallScorePercent >= 95)
19376 Rating =
"Excellent";
19378 else if(OverallScorePercent >= 90)
19380 Rating =
"Very good";
19382 else if(OverallScorePercent >= 80)
19386 else if(OverallScorePercent >= 70)
19390 else if(OverallScorePercent >= 60)
19392 Rating =
"Unacceptable" + AddedString;
19394 else if(OverallScorePercent >= 50)
19396 Rating =
"Poor" + AddedString;
19398 else if(OverallScorePercent >= 40)
19400 Rating =
"Bad" + AddedString;
19402 else if(OverallScorePercent >= 30)
19404 Rating =
"Very bad" + AddedString;
19406 else if(OverallScorePercent >= 20)
19408 Rating =
"Terrible" + AddedString;
19410 else if(OverallScorePercent >= 10)
19412 Rating =
"Appalling" + AddedString;
19414 else if(OverallScorePercent >= 5)
19418 Rating =
"Disastrous - potential loss of life";
19423 Rating =
"Dire" + AddedString;
19426 else if(OverallScorePercent < 5)
19430 Rating =
"Catastrophic - loss of life";
19434 Rating =
"Abysmal";
19437 PerfFile <<
"Overall rating: " << Rating.c_str() <<
'\n';
19441 PerfFile <<
"\nThere were no timetabled departures, arrivals or exits so there is insufficient information to provide a performance score or rating" <<
'\n';
19443 PerfFile <<
'\n' <<
"***************************************";
19452 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
19502 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
19537 int IncrementalMinutes = 0;
19551 bool TrainOperatingFlag =
false;
19556 TrainOperatingFlag =
true;
19560 if(TrainOperatingFlag)
19568 for(
unsigned int z = 0; z < TDEntry.
ActionVector.size(); z++)
19615 AnsiString HeadCode;
19619 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
19623 HCandTrainPosParam.first = HeadCode;
19624 HCandTrainPosParam.second = TrainID;
19626 if((TimeToAct >= 0) && (TimeToAct < 59.9))
19629 OpTimeToActMultiMapEntry.first = TimeToAct;
19630 OpTimeToActMultiMapEntry.second = HCandTrainPosParam;
19659 float TimeToAct = 0;
19660 int DistanceToRedSignal = 0;
19663 ContinuationEntryVecPosVector.clear();
19664 bool LaterTrain =
false;
19668 LaterTrain =
false;
19669 if(CTEIt->second.TrainDataEntryPtr->TrainOperatingDataVector.at(CTEIt->second.RepeatNumber).RunningEntry !=
NotStarted)
19680 if(!ContinuationEntryVecPosVector.empty())
19682 for(
unsigned int x = 0; x < ContinuationEntryVecPosVector.size(); x++)
19684 if(CTEIt->second.VectorPosition == ContinuationEntryVecPosVector.at(x))
19698 ContinuationEntryVecPosVector.push_back(CTEIt->second.VectorPosition);
19699 AnsiString HeadCode = CTEIt->second.HeadCode;
19700 float CurrentStopTime;
19701 float LaterStopTime;
19702 float RecoverableTime;
19705 int DistanceToExit;
19707 bool SigControlAndCanPassRedSignal =
false;
19715 if(CTEIt->second.TrainDataEntryPtr->ActionVector.size() == 1)
19721 SigControlAndCanPassRedSignal, &CTEIt->second.TrainDataEntryPtr->ActionVector.at(AtValue),
19722 HeadCode, TrainID, CurrentStopTime, LaterStopTime, RecoverableTime, AvTrackSpeed, DistanceToExit, ExitPair);
19725 if(AvTrackSpeed < 30)
19729 if(DistanceToRedSignal == -1)
19735 int Speed = AvTrackSpeed;
19736 int MaxSpeed = int(CTEIt->second.TrainDataEntryPtr->MaxRunningSpeed);
19737 if(AvTrackSpeed > MaxSpeed)
19741 if(CTEIt->second.TrainDataEntryPtr->ActionVector.at(0).SignallerControl)
19744 Speed = CTEIt->second.TrainDataEntryPtr->SignallerSpeed;
19747 TimeToAct = LaterStopTime + DistanceToRedSignal * 3.6 / 60 / Speed;
19752 float MinsBefEnter = double(CTEIt->first -
TTClockTime) * 86400.0 / 60.0;
19753 TimeToAct += MinsBefEnter;
19756 HCandTrainPosParam.first = HeadCode;
19757 HCandTrainPosParam.second = -1 - CTEIt->second.VectorPosition;
19760 if(TimeToAct < 59.9)
19762 OpTimeToActMultiMapEntry.first = TimeToAct;
19763 OpTimeToActMultiMapEntry.second = HCandTrainPosParam;
19788 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
19798 TimeToExitMultiMapEntry.first = ExitPair;
19799 TimeToExitMultiMapEntry.second = ExitInfo;
19809 bool SigControlAndCanPassRedSignal,
TActionVectorEntry *AVPtr, AnsiString HeadCode,
int TrainID,
float &CurrentStopTime,
float &LaterStopTime,
19810 float &RecoverableTime,
int &AvTrackSpeed,
int &DistanceToExit,
THVShortPair &ExitPair)
19819 AnsiString(TrackVectorPositionEntryPos) +
", " + AVPtr->
Command);
19820 int DistanceToRedSignal = 0;
19821 DistanceToExit = -1;
19822 ExitPair.first = -1;
19823 ExitPair.second = -1;
19824 int CumTrackSpeed = 0;
19826 int TrackSpeedCount = 0;
19827 float KmPerLocationStop;
19828 float MaxAllowableSpeed;
19838 int CurrentElement = TrackVectorPosition;
19839 int CurrentEntryPos = TrackVectorPositionEntryPos;
19844 CurrentStopTime = 0;
19846 RecoverableTime = 0;
19847 if(CurrentElement == -1)
19852 int CurrentExitPos;
19857 if((CurrentEntryPos == 0) || (CurrentEntryPos == 2))
19861 CurrentExitPos = 1;
19865 CurrentExitPos = 3;
19870 CurrentExitPos = 0;
19906 CurrentStopTime = float(TimeToDepart);
19912 if((CurrentExitConfig ==
Signal) && (CurrentAttribute == 0))
19923 else if(SigControlAndCanPassRedSignal)
19928 if((NextEntryPos == 0) || (NextEntryPos == 2))
19949 CurrentElement = NextElement;
19950 CurrentEntryPos = NextEntryPos;
19951 CurrentExitPos = NextExitPos;
19963 int LaterStopNumber = 0;
19967 while(!((CurrentExitConfig ==
Signal) && (CurrentAttribute == 0)))
19976 if(CurrentEntryPos > 1)
19991 DistanceToExit = DistanceToRedSignal;
19996 if(TrackSpeedCount > 0)
19998 MaxAllowableSpeed = CumTrackSpeed / TrackSpeedCount;
20002 if(CurrentEntryPos > 1)
20013 if(LaterStopNumber > 0)
20015 KmPerLocationStop = float(DistanceToRedSignal) / LaterStopNumber / 1000;
20016 AvTrackSpeed = (8.75 * KmPerLocationStop) + 44;
20022 AvTrackSpeed = (sqrt(
float(DistanceToRedSignal) / 1000) * 44) + 60;
20026 if(AvTrackSpeed > MaxAllowableSpeed)
20028 AvTrackSpeed = MaxAllowableSpeed;
20040 bool StopRequired =
false;
20057 int TrainOnElement;
20064 if(CurrentEntryPos > 1)
20073 if((TrainOnElement > -1) && (TrainOnElement != TrainID))
20082 double StopTimeDouble;
20095 if(StopTimeDouble < 0.5)
20097 StopTimeDouble = 0.5;
20101 LaterStopTime += float(StopTimeDouble);
20102 RecoverableTime += StopTimeDouble - 0.5;
20103 if((LaterStopNumber == 1) && (TrainID > -1))
20111 if((AVPtr + 1)->FormatType ==
TimeLoc)
20115 StopTimeDouble = double((AVPtr + 1)->DepartureTime - AVPtr->
ArrivalTime) * 86400.0 / 60.0;
20117 if(StopTimeDouble < 0.5)
20119 StopTimeDouble = 0.5;
20122 LaterStopTime += float(StopTimeDouble);
20123 RecoverableTime += StopTimeDouble - 0.5;
20124 if((LaterStopNumber == 1) && (TrainID > -1))
20140 if(NextElement == -1)
20149 if((NextEntryPos == 0) || (NextEntryPos == 2))
20170 CurrentElement = NextElement;
20171 CurrentEntryPos = NextEntryPos;
20172 CurrentExitPos = NextExitPos;
20176 if((CurrentExitConfig ==
Signal) && (CurrentAttribute == 0))
20189 if(TrackSpeedCount > 0)
20191 MaxAllowableSpeed = CumTrackSpeed / TrackSpeedCount;
20195 if(CurrentEntryPos > 1)
20206 if(LaterStopNumber > 0)
20208 KmPerLocationStop = float(DistanceToRedSignal) / LaterStopNumber / 1000;
20209 AvTrackSpeed = (8.75 * KmPerLocationStop) + 44;
20215 AvTrackSpeed = (sqrt(
float(DistanceToRedSignal) / 1000) * 44) + 60;
20219 if(AvTrackSpeed > MaxAllowableSpeed)
20221 AvTrackSpeed = MaxAllowableSpeed;
20224 return(DistanceToRedSignal);